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: Why isn't this respawn script working?

Previous Thread :: Next Thread 
whyOmustOitObeOme is not online. whyOmustOitObeOme
Joined: 29 Aug 2009
Total Posts: 15668
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
whyOmustOitObeOme is not online. whyOmustOitObeOme
Joined: 29 Aug 2009
Total Posts: 15668
02 Mar 2015 05:30 PM
bump
Report Abuse
XtremeTemper is not online. XtremeTemper
Joined: 02 Mar 2012
Total Posts: 1774
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
whyOmustOitObeOme is not online. whyOmustOitObeOme
Joined: 29 Aug 2009
Total Posts: 15668
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
XtremeTemper is not online. XtremeTemper
Joined: 02 Mar 2012
Total Posts: 1774
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
whyOmustOitObeOme is not online. whyOmustOitObeOme
Joined: 29 Aug 2009
Total Posts: 15668
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
XtremeTemper is not online. XtremeTemper
Joined: 02 Mar 2012
Total Posts: 1774
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
whyOmustOitObeOme is not online. whyOmustOitObeOme
Joined: 29 Aug 2009
Total Posts: 15668
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
BIoodraven is not online. BIoodraven
Joined: 14 Sep 2014
Total Posts: 11981
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
whyOmustOitObeOme is not online. whyOmustOitObeOme
Joined: 29 Aug 2009
Total Posts: 15668
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 is not online. 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
FrostBiteFreshy is not online. FrostBiteFreshy
Joined: 10 Mar 2013
Total Posts: 263
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 is not online. 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
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