|
| 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
|
  |
| 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 |
|
|
|
| 09 Nov 2017 03:21 PM |
| Can you show me what that would look like? |
|
|
| Report Abuse |
|
|
|
| 09 Nov 2017 03:26 PM |
| Ah, thanks for the tip! I got it figured out :D |
|
|
| Report Abuse |
|
|
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
|
  |
| 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
|
  |
| 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 |
|
|