Hey devs!
I’m trying to create a main menu in my game where the player is frozen (WalkSpeed = 0) until they press a “Play” button. This works fine at first, but when players die and respawn during the match, they sometimes stay frozen and can’t move.
Here’s what I’ve tried so far:
-
CharacterAdded event to set
WalkSpeed
back to 16 after the player respawns. -
Checking if the player is in the menu (
isInMenu
flag) to control movement. - Humanoid.Died event to reset movement.
However, the issue persists, and the player often stays frozen even when they respawn during the match. I’d love to know:
- How do I ensure WalkSpeed is always reset on respawn during the match?
- Is there a more reliable way to freeze/unfreeze the player only when they’re in the menu?
also here is the script that i used:
local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera
local menuCameraPosition = workspace:WaitForChild("MenuScene"):WaitForChild("MenuCameraPosition")
local mainMenuGui = player:WaitForChild("PlayerGui"):WaitForChild("MainMenuGui")
local isInMenu = true
local function setPlayerMovement(walkSpeed, jumpPower)
if player.Character then
local humanoid = player.Character:FindFirstChild("Humanoid")
if humanoid then
humanoid.WalkSpeed = walkSpeed
humanoid.JumpPower = jumpPower
end
end
end
local function enterMenu()
isInMenu = true
setPlayerMovement(0, 0)
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = menuCameraPosition.CFrame
mainMenuGui.Enabled = true
end
local function exitMenu()
isInMenu = false
setPlayerMovement(16, 50)
camera.CameraType = Enum.CameraType.Custom
mainMenuGui.Enabled = false
end
player.CharacterAdded:Connect(function(character)
local humanoid = character:WaitForChild("Humanoid")
humanoid.Died:Connect(function()
if not isInMenu then
setPlayerMovement(16, 50)
end
end)
if isInMenu then
setPlayerMovement(0, 0)
else
setPlayerMovement(16, 50)
end
end)
local playButton = mainMenuGui:FindFirstChild("PlayButton")
if playButton then
playButton.MouseButton1Click:Connect(exitMenu)
end
enterMenu()
Any help would be appreciated! Thanks!