So I'm making a game and I don't want the player to actually die or it'll break the game. (common problem with other games) So I made a script where when someone is under 5 health, they will be teleported to a sort of "death scene." But the script won't work. (I only did the part where you get teleported, I might make a new question will more script.)
player = game.Players:GetChildren() playerfind = player:GetFullName() wplayer = game.Workspace.playerfind while true do if player.Humanoid.Health > 5 then wplayer.Character.Torso.CFrame = CFrame.new(-59.8, 0.5, 78.2) end end
Help?
Your script is using a while true do loop without a wait which crashes the script. Also you're checking if the player's health is greater than 5, not less than 5. You should use the HealthChanged
event instead of a while loop. The localscript below should work for you.
--- LOCALSCRIPT (place this into the starterpack) local runservice = game:GetService'RunService' local players = game:GetService'Players' repeat runservice.RenderStepped:wait() until players.LocalPlayer and players.LocalPlayer.Character local player = players.LocalPlayer local character = player.Character local torso = character:WaitForChild'Torso' local humanoid = character:WaitForChild'Humanoid' humanoid.HealthChanged:connect(function(health) -- USE THIS EVENT, NOT A WHILE LOOP if health <= 5 then torso.CFrame = CFrame.new(-59.8, 0.5, 78.2) end end)