Character cannot move even with controls enabled = true

My output says my controlsenabled is on but when I try to move, it doesn’t work

However whenever I change movement mode (such as click to move) and then use it, my controls work again?

I’m not sure if this is a bug or something wrong with my code:

local Players = game:GetService("Players")

local function onCharacterAdded(player, character)
    local plrscripts = player:WaitForChild("PlayerScripts")
    local module = require(plrscripts:WaitForChild("PlayerModule"))
    local controls = module:GetControls()

    if player:GetAttribute("Menu") == true then
        if player.PlayerGui:FindFirstChild("StaminaGui") then
            player.PlayerGui.StaminaGui.Enabled = false
        end
        controls:Disable()
        print("Controls disabled for player:", player.Name)
    else
        if player.PlayerGui:FindFirstChild("StaminaGui") then
            player.PlayerGui.StaminaGui.Enabled = true
        end
        if controls.controlsEnabled == false or controls.controlsEnabled == nil then
            controls:Enable(true)
            print("Controls enabled for player:", player.Name)
        end
	end
	print(controls.controlsEnabled)
end

local function onPlayerAdded(player)
    player.CharacterAdded:Connect(function(character)
        onCharacterAdded(player, character)
    end)
    -- If character already exists (player joined after respawn), handle it
    if player.Character then
        onCharacterAdded(player, player.Character)
    end
end

Players.PlayerAdded:Connect(onPlayerAdded)
-- Handle players already in game
for _, player in Players:GetPlayers() do
    onPlayerAdded(player)
end
1 Like

Hmm I would add a tiny delay before you try to require the player module. Perhaps it works when switching movement mode is because it forces to reinitialise the player module.

try:

local function onCharacterAdded(player, character)
    task.delay(0.1, function()
        local plrscripts = player:WaitForChild("PlayerScripts")
        local success, module = pcall(function()
            return require(plrscripts:WaitForChild("PlayerModule"))
        end)

        if not success then
            warn("Failed to require PlayerModule for", player.Name)
            return
        end

        local controls = module:GetControls()
-- Rest of code here
end
1 Like

Thanks for the help but that doesn’t seem to do anything, I’ve found a solution which is seems kind of janky though.

All I needed to do is disable controls right before I enable them again, but I also had to remove the if control.controlsEnabled == false since it was basically useless

Ah yes, that would’ve been my second guess. But glad you found the solution to it though! Well done!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.