Mobile Jump Button not working after respawning

My code messes around with controls every time the player respawns, except the controls are enabled as the player can move on both pc and mobile, and the player can jump on pc, but for some reason the jump button on mobile does not work at all. Can anybody help out with this?

local Players = game:GetService("Players")
local con = game.ReplicatedStorage:WaitForChild("Controls")
local plr = Players.LocalPlayer


local function onCharacterAdded(player, character)
    local plrscripts = player:WaitForChild("PlayerScripts")
    local module = require(plrscripts:WaitForChild("PlayerModule"))
    local controls = module:GetControls()
	local mobile = player.PlayerGui:WaitForChild("Mobile")
	
    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.Objective.Frame.Visible = true
			mobile:FindFirstChild("Frame").Visible = true
			player.PlayerGui.StaminaGui.Enabled = true
		end
		print("Controls enabled for player:", player.Name)
		local humanoid = character.Humanoid
			
		controls:Disable()
		controls:Enable(true)
	end	
	
end

local function onPlayerAdded(player)
	player.CameraMaxZoomDistance=15
	
    player.CharacterAdded:Connect(function(character)
        onCharacterAdded(player, character)
	end)
	
    if player.Character then
        onCharacterAdded(player, player.Character)
	end
end

Players.PlayerAdded:Connect(onPlayerAdded)

con.Event:Connect(function(plrr)
	onPlayerAdded(plrr)
end)


for _, player in Players:GetPlayers() do
    onPlayerAdded(player)
end

1 Like

Can you show us the code please?

Oh yeah sorry I forgot about that I’ve added it to the main post now but I’m not sure if this is the particular code causing the problem

1 Like

So what are you trying to achieve with this code? Like stop the player movement or what.

Yeah basically it stops the players movement if they’re on the main menu

1 Like

Um so i have a simpler method to do that but i do not know how optimized it is but i always use it. You can just anchor the player or you can just set their walkspeed to 0 and jump power to 0 in starter player

1 Like

local hrp = game.Players.LocalPlayer.Character:WaitForChild(“HumanoidRootPart”)
hrp.Anchored = true

1 Like

The only thing is though I don’t know how you are using this so maybe this is not the best fit for you.

1 Like

Thanks for the help but it seems like I found a solution that still doesn’t really make any sense, all I had to do was add a wait() before the first controls:Disable() in the script and now the mobile jump button works again

1 Like

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