|
| 02 Mar 2015 05:08 PM |
I have a script inside the StarterGui that is supposed to fire whenever a player dies. Here's the script (the script isn't a localscript):
local player = script.Parent.Parent repeat wait() until player.Character repeat wait() until player.Character:findFirstChild("Humanoid") player.Character.Humanoid.Changed:connect(function() repeat wait() until player.Character if player.Character.Humanoid.Health <= 0 then print'dead' wait(4) player:LoadCharacter() repeat wait() until player.Character player.Character.Torso.CFrame = CFrame.new(game.Workspace.teleportPlayerHere.Position) player.Character.ForceField:Destroy() end end)
The script works fine the first time a player dies, but it doesn't do anything the second time. There isn't anything in the output when the player dies the second time. Any help? |
|
|
| Report Abuse |
|
|
| |
|
|
| 02 Mar 2015 05:34 PM |
local player = script.Parent.Parent player.CharacterAdded:connect(function() player.Character.Humanoid.Changed:connect(function() if player.Character.Humanoid.Health <= 0 then print'dead' wait(4) player:LoadCharacter() repeat wait() until player.Character player.Character.Torso.CFrame = CFrame.new(game.Workspace.teleportPlayerHere.Position) player.Character.ForceField:Destroy() end end) end)
Try that? and why is this inside a GUI? |
|
|
| Report Abuse |
|
|
|
| 02 Mar 2015 05:38 PM |
"local player = script.Parent.Parent player.CharacterAdded:connect(function() player.Character.Humanoid.Changed:connect(function() if player.Character.Humanoid.Health <= 0 then print'dead' wait(4) player:LoadCharacter() repeat wait() until player.Character player.Character.Torso.CFrame = CFrame.new(game.Workspace.teleportPlayerHere.Position) player.Character.ForceField:Destroy() end end) end)"
This is a paradox... the script will only activate once the player respawns, but the script inside it is the only thing that makes the player respawn. CharacterAutoLoads is turned off btw. |
|
|
| Report Abuse |
|
|
|
| 02 Mar 2015 05:41 PM |
| Why not make a script in workspace that detects when a player dies and respawns them. Its prob not working correctly because its in a gui? Im not sure. |
|
|
| Report Abuse |
|
|
|
| 02 Mar 2015 05:41 PM |
| There shouldn't be a difference between putting it in workspace and in PlayerGui. I set the PlayerGui to not reset when the player dies. |
|
|
| Report Abuse |
|
|
|
| 02 Mar 2015 05:43 PM |
| Gui's are weird, I dont put anything in them except Gui's and scripts that need the mouse....Just try my idea? Im just skimming your script, let me look more into it. |
|
|
| Report Abuse |
|
|
|
| 02 Mar 2015 05:45 PM |
| The main reason why it's inside the PlayerGui is to get the player with using a PlayerAdded function. |
|
|
| Report Abuse |
|
|
|
| 02 Mar 2015 06:03 PM |
--local script local player = game.Players.LocalCharacter local character = player.Character or player.CharacterAdded:wait() local humanoid = character:WaitForChild('Humanoid') humanoid.Died:connect(function() print('dead lol rekt noob') wait(4) player:LoadCharacter() end)
"no you're being stupid." -General Astrochemistry |
|
|
| Report Abuse |
|
|
|
| 02 Mar 2015 06:04 PM |
@Blood
:LoadCharacter() doesn't work in a localscript.
I fixed the script anyway. At the end of the code, I cloned the script and deleted the previous one. It's a rather sloppy fix, but hey, at least it works. |
|
|
| Report Abuse |
|
|
Taryo
|
  |
| Joined: 06 Aug 2011 |
| Total Posts: 496 |
|
|
| 02 Mar 2015 06:06 PM |
| Hmm, could it be because once your script ends, it is done and won't repeat, or am I thinking of a different instance? |
|
|
| Report Abuse |
|
|
|
| 02 Mar 2015 06:09 PM |
Could be the local player part is the script directly in StarterGui or is it in a separate Gui because if it's in a separate Gui then the correction would be made with the parents
local player = script.Parent.Parent.Parent
script>SeparateGui>StarterGui>player |
|
|
| Report Abuse |
|
|
Taryo
|
  |
| Joined: 06 Aug 2011 |
| Total Posts: 496 |
|
|
| 02 Mar 2015 06:20 PM |
--Try this, and put the script itself in the Startergui. local Player = "" Player = script.Parent.Parent.Name -- Just to make sure it doesn't think it's a nil value. while true do if game.Workspace:FindFirstChild(Player).Humanoid.Health <= 0 then -- Just a little longer since the previous wasn't working print'Dead' wait(0.5) script.Parent.Parent:LoadCharacter local QuickPlr = game.Workspace:FindFirstChild(Player) QuickPlr.Torso.CFrame = CFrame.new(game.Workspace.teleportPlayerHere.Position) if QuickPlr:FindFirstChild("ForceField") then QuickPlr.ForceField:remove() end end wait(0.1) end
-- OR, This will do the trick for you, I just think you're waiting too long.
local player = script.Parent.Parent repeat wait() until player.Character repeat wait() until player.Character:findFirstChild("Humanoid") player.Character.Humanoid.Changed:connect(function() repeat wait() until player.Character if player.Character.Humanoid.Health <= 0 then print'dead' wait(0.05) player:LoadCharacter() repeat wait() until player.Character player.Character.Torso.CFrame = CFrame.new(game.Workspace.teleportPlayerHere.Position) if player.Character:FindFirstChild("ForceField") then player.Character.ForceField:Destroy() end end end) |
|
|
| Report Abuse |
|
|