Player unable to walk after respawning?

Hello, I have a script that’s making the player automatically walk towards a part. I just don’t want the player to be able to move during that time, so I’m using this code to do so:

wait()

local player = game.Players.LocalPlayer
local character = player.Character
local walkable = character:FindFirstChild("Walkable")

while true do
	wait()
	if walkable then
		if walkable.Value == true then
			local Controller = require(game.Players.LocalPlayer:WaitForChild("PlayerScripts"):WaitForChild("PlayerModule")):GetControls()
			Controller:Enable()
		elseif walkable.Value == false then
			local Controller = require(game.Players.LocalPlayer:WaitForChild("PlayerScripts"):WaitForChild("PlayerModule")):GetControls()
			Controller:Disable()
		end
		character.Humanoid.Died:Connect(function()
			local Controller = require(game.Players.LocalPlayer:WaitForChild("PlayerScripts"):WaitForChild("PlayerModule")):GetControls()
			Controller:Enable()
		end)
	end
end

If they die while the controls are disabled, they won’t be able to move when they respawn. I’ve tried re-enabling it after the character is added, but it won’t work. If anyone can help, that would be a big help! Thanks in advance!

2 Likes

The problem will be in the Event, I think the code will run but it will do not connect to Died Event,
You should make another script where you connect this event and code it.

2 Likes

I’ve tried doing “print” inside the event, and it ran fine.

1 Like

Can’t you just anchor the players root part?
It should be that easy if you just want to disable the movement.

2 Likes

Sorry, I forgot to mention that I’m using a script that makes the player automatically walk to a part. I simply want to remove the ability to walk without changing the walkspeed.

2 Likes

Oh, sorry I can’t help you with that then. I’m truly sorry I can’t help you with this.

I don’t really understand players that much so I can’t really help.

2 Likes

Don’t worry about it! :slight_smile:

2 Likes

Where did you place the script in?

Also, sorry if I make your script get a error. I’m a basic scripter, and a medium builder.

Thanks,
HDAdminUnofficial

I had the same problem after disableling the controls and the player died, the controls would stop working even if I used the Controls:Enable() after the player respawned, but this is how I fixed it.
Inside a local script in StartedCharacterScripts folder I added this following code:

local LocalPlayer = game:GetService("Players").LocalPlayer
local playerModule = require(LocalPlayer.PlayerScripts:WaitForChild("PlayerModule"))
local controls = playerModule:GetControls()
controls:Disable()
wait()
controls:Enable()

I put this before any of my functions(am guessing it could go anywhere as long as it gets excecuted at the beggening)
side note just know that any scripts inside StartedCharacterScripts will reset every time the player respawns

6 Likes

Try this:

local player = game.Players.LocalPlayer
local character = player.Character
local walkable = character:FindFirstChild("Walkable")

while true do
	task.wait()
	if walkable then
		if walkable.Value == true then
			local Controller = require(game.Players.LocalPlayer:WaitForChild("PlayerScripts"):WaitForChild("PlayerModule")):GetControls()
			Controller:Enable()
		elseif walkable.Value == false then
			local Controller = require(game.Players.LocalPlayer:WaitForChild("PlayerScripts"):WaitForChild("PlayerModule")):GetControls()
			Controller:Disable()
		end
	end
end

character.Humanoid.Died:Connect(function()
	local Controller = require(game.Players.LocalPlayer:WaitForChild("PlayerScripts"):WaitForChild("PlayerModule")):GetControls()
	Controller:Enable()
end)

Do this:

local player = game.Players.LocalPlayer
local Controller = require(player:WaitForChild("PlayerScripts"):WaitForChild("PlayerModule")):GetControls()

player.CharacterAdded:Connect(function(char)
	local walkable = char:FindFirstChild("Walkable")
	char.Humanoid.Died:Connect(function()
		Controller:Disable()
	end)
    Controller:Enable()
	while task.wait() do
		if walkable then
			if walkable.Value then
				Controller:Enable()
			elseif not walkable.Value then
				Controller:Disable()
			end
		end
	end
end)

So that it detects the Died event before it loops.

Move script to StarterCharacterScripts.

local players = game:GetService("Players")
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local playerScripts = player:WaitForChild("PlayerScripts")
local playerModule = playerScripts:WaitForChild("PlayerModule")
playerModule = require(playerModule)
local controller = playerModule:GetControls()
controller:Enable()

local walkable = character:FindFirstChild("Walkable")

if walkable then
	walkable.Changed:Connect(function(newVal)
		if newVal then
			controller:Enabled()
		elseif not newVal then
			controller:Disable()
		end
	end)
end