Player controls remains re-disabled after death

I’ve tried making some script which blocked any player movement while an animation is played, but apparently when the player dies, somewhy, the Controls get re-disabled. Does anyone know why?

local plr = game.Players.LocalPlayer
local char = plr.Character

local PlayerModule = require(plr.PlayerScripts:WaitForChild("PlayerModule"))
local Controls = PlayerModule:GetControls()

game.ReplicatedStorage.AnimationEvent.OnClientEvent:Connect(function(test_subject)
	if char:FindFirstChild("IsPlayable") then
		local animation = Instance.new("Animation")
		local animation3 = Instance.new("Animation")
		local hum = char:FindFirstChild("Humanoid")
		animation.Parent = char
		animation.AnimationId = "rbxassetid://IDHERE"
		animation3.Parent = char
		animation3.AnimationId = "rbxassetid://IDHERE"
		local loadedTrack = hum:LoadAnimation(animation)
		local loadedTrack3 = hum:LoadAnimation(animation3)
		Controls:Disable()
		loadedTrack:Play()
		loadedTrack.Stopped:wait(loadedTrack.Length-.5)
		loadedTrack3:Play()
		loadedTrack3.Stopped:wait()
		Controls:Enable()
	end
end)

plr.CharacterAdded:Connect(function()
	Controls:Enable()
end)
1 Like

local scripts restart after a player dies, it might have something to do with that.

I had this problem too, I just added

Controls:Disable()
Controls:Enable()

after the controls = variable and it fixed the problem.

2 Likes

It works, thank you very much!

Actually broke again, I assume there’s some issue within the PlayerModule, so I fixed it by setting char.HumanoidRootPart.Anchored = true and then put it false.
EDIT: Now the player can’t rotate too, which makes the animation more realistic.

1 Like