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