generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Script counts for all players

Previous Thread :: Next Thread 
milanomaster is not online. milanomaster
Joined: 22 Jan 2013
Total Posts: 252
09 Nov 2017 03:03 PM
The script below somehow counts for every single player. When ANY player has died, their lives counter drops but everyones value drops. How can I make it so it only affects ONE player?
[ script in Workspace ]
[ game is in FE ]

Thanks in advance!


local livescountergui = game.StarterGui:WaitForChild("Lives")
local destinationID = #########

local lives = 3

game:GetService("Players").PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(loaded)
local human = loaded:WaitForChild("Humanoid")
if human then
human.Died:Connect(function()
lives = lives - 1
livescountergui.Frame.TextLabel.Text = 'Lives left: '..lives..''
end)
if lives == 0 then
game:GetService("TeleportService"):Teleport(destinationID , player)
end
end
end)
end)
Report Abuse
UgOsMiLy is not online. UgOsMiLy
Joined: 15 Sep 2009
Total Posts: 2095
09 Nov 2017 03:19 PM
the lives variable is outside the functions, so when it changes for 1 player, it will affect them all. What you should probably do is put an IntValue in the player and take it away by 1, in the script.


Report Abuse
milanomaster is not online. milanomaster
Joined: 22 Jan 2013
Total Posts: 252
09 Nov 2017 03:21 PM
Can you show me what that would look like?
Report Abuse
milanomaster is not online. milanomaster
Joined: 22 Jan 2013
Total Posts: 252
09 Nov 2017 03:26 PM
Ah, thanks for the tip! I got it figured out :D
Report Abuse
soutenu is online. soutenu
Joined: 09 Dec 2011
Total Posts: 1021
09 Nov 2017 03:30 PM
you would have to create the lives variable under the PlayerAdded scope so that each player would have their own variable rather than sharing one
Report Abuse
iiNemo is online. iiNemo
Joined: 22 Jul 2013
Total Posts: 2380
09 Nov 2017 03:36 PM
local TS = game:GetService('TeleportService') local PS = game:GetService('Players') local PlayerLives = {} PS.PlayerAdded:Connect(function(Player) PlayerLives[Player] = 3 Player.CharacterAdded:Connect(function(Character) Character:WaitForChild('Humanoid').Died:Connect(function() if PlayerLives[Player] then PlayerLives[Player] = PlayerLives[Player] - 1 if Player.PlayerGui then Player.PlayerGui.Frame.TextLabel.Text = 'Lives Left: '..PlayerLives[Player] end if PlayerLives[Player] <= # #### #################### Player) end end end) end) end) PS.PlayerRemoving:Connect(function(Player) if PlayerLives[Player] then PlayerLives[Player] = nil end end) Fish Are Friends, Not Food
Report Abuse
iiNemo is online. iiNemo
Joined: 22 Jul 2013
Total Posts: 2380
09 Nov 2017 03:38 PM
local PlaceId = PLACEIDHERE

local TS = game:GetService('TeleportService')
local PS = game:GetService('Players')

local PlayerLives = {}

PS.PlayerAdded:Connect(function(Player)
PlayerLives[Player] = 3
Player.CharacterAdded:Connect(function(Character) Character:WaitForChild('Humanoid').Died:Connect(function()
if PlayerLives[Player] then
PlayerLives[Player] = PlayerLives[Player] - 1
if Player.PlayerGui then
Player.PlayerGui.Frame.TextLabel.Text = 'Lives Left: '..PlayerLives[Player]
end
if PlayerLives[Player] <= 0 then
TS:Teleport(PlaceId, Player)
end
end
end)
end)
end)

PS.PlayerRemoving:Connect(function(Player)
if PlayerLives[Player] then
PlayerLives[Player] = nil
end
end)



Fish Are Friends, Not Food
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image