Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to make a script run even after the player death?

I have a local script that works fine but after the player resets it stops working.

_G.Toggle = true

while _G.Toggle == true do

game:GetService("Players").LocalPlayer.Backpack.Combat.RemoteEvent:FireServer("comboAttack")

game:GetService("Workspace").suricato006.HumanoidRootPart.CFrame = game:GetService("Workspace").FightableNPC.ROSHIStarter.rock.HumanoidRootPart.CFrame wait()

end

now the script is supposed to spam teleport the player and making it attack automatically but it doesnt work when he resets. The problem that i think it can be is the fact that the Character model re-builds when the player dies so there is no HumanoidRootPart and the script stops working cause it errors. How can i fix it? I tried putting a game.Workspace.suricato006:WaitForChild("HumanoidRootPart") but still.

1 answer


game:GetService('Players').PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		character:WaitForChild("Humanoid").Died:Connect(function()
                       -- Your code
		end)
	end)
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.