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

How do I make it where if a player dies, they can move after 10 seconds is over?

local Death = script.DeathAnimations
local plr = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
hum.BreakJointsOnDeath = false

plr.CharacterAdded:connect(function(char)
	char:WaitForChild("Humanoid"):SetStateEnabled(Enum.HumanoidStateType.Dead, false)
end)



hum.Died:Connect(function()
	game.StarterGui:SetCoreGuiEnabled("Backpack", false)
	char.HumanoidRootPart.Anchored = true
	hum:UnequipTools()
	script.Parent.RemoteEvent:FireServer()
	local DeathAnimation = hum:LoadAnimation(Death)
	DeathAnimation:Play()
	wait(10)
	char.HumanoidRootPart.Anchored = false
	script.Parent.RemoteEvent2:FireServer()
	game.StarterGui:SetCoreGuiEnabled("Backpack", true)
end)

1 answer

You can use the 'PlayerModule' that is built in to disable and enable movement.

local Movement = require(game.Players.LocalPlayer.PlayerScripts.PlayerModule):GetControls()
local Death = script.DeathAnimations
local plr = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
hum.BreakJointsOnDeath = false

plr.CharacterAdded:connect(function(char)
    char:WaitForChild("Humanoid"):SetStateEnabled(Enum.HumanoidStateType.Dead, false)
end)



hum.Died:Connect(function()
    game.StarterGui:SetCoreGuiEnabled("Backpack", false)
    char.HumanoidRootPart.Anchored = true
    hum:UnequipTools()
    script.Parent.RemoteEvent:FireServer()
    local DeathAnimation = hum:LoadAnimation(Death)
    DeathAnimation:Play()
    Movement:Disable()
    wait(10)
    Movement:Enable()
    char.HumanoidRootPart.Anchored = false
    script.Parent.RemoteEvent2:FireServer()
    game.StarterGui:SetCoreGuiEnabled("Backpack", true)
end)

1 comment

0

Still not able to move. Not sure what I'm doing wrong.

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