Hello, I'm trying to make a character customization and I have a problem, I want to make the player not move when the GUI is displayed and can move if the GUI is not displayed.
I tried this:
local plr = game.Players.LocalPlayer local char = plr.Character while script.Parent.Parent == plr.PlayerGui do char:FindFirstChild("UpperTorso").Anchored = true end while not script.Parent.Parent == plr.PlayerGui do char:FindFirstChild("UpperTorso").Anchored = false end
And this:
local plr = game.Players.LocalPlayer local plrname = game.Players.LocalPlayer.Name local char = game.Workspace:FindFirstChild(plrname) while script.Parent.Parent == plr.PlayerGui do char:FindFirstChild("UpperTorso").Anchored = true end while not script.Parent.Parent == plr.PlayerGui do char:FindFirstChild("UpperTorso").Anchored = false end
Nothing worked, By the way I tried doing if ... then, Except of the while ... do and I'm using it in a LocalScript
Thanks, MajinBluee
game.Players.LocalPlayer.PlayerScripts.ControlScript.Disabled = true
So add WaitForChild()
function to wait until the character is in workspace
Seeing this code it will not work with Filtered enabled since you are anchoring a the torso in the local script it will only be achored on client game and not on server
Read more on how to make it Filtered enabled https://wiki.roblox.com/index.php?title=Remote_Functions_%26_Events
local plr = game.Players.LocalPlayer local plrname = game.Players.LocalPlayer.Name local char = game.Workspace:WaitForChild(plrname) --Added it all in one while since the program will never have reached the second while while true do if script.Parent.Parent == plr.PlayerGui then char:FindFirstChild("UpperTorso").Anchored = true else char:FindFirstChild("UpperTorso").Anchored = false end wait(0.5) end
Now there is a better way to do this instead of checking every 0.5 seconds if the player has gui. This is too much process intensive I think.
You could also try this:
-- Place script inside of the gui. Also make sure that the script is a local script local toggle = false local Humanoid = game.Players.LocalPlayer.Character:FindFirstChild("Humanoid") script.Parent.TextButton.MouseButton1Click:Connect(function() if toggle == false then toggle = true script.Parent.Frame.Visible = true Humanoid.WalkSpeed = 0 else Humanoid.WalkSpeed = 16 script.Parent.Frame.Visible = false toggle = false end end)