Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Trying to make a Can't Move script but the script doesn't work? This title is specific

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

9 comments

0

Yay now this title is specific

0

Is that in script or local script?

0

Does your game force R15 or is it Player's Choice? Because if it IS Player's Choice then you would have to do both "UpperTorso" (R15) and "Torso" (R6).

0

I said i'm using it in a script and it's forced to be R15

0

Oh, okay.

0

Then try anchoring the HumanoidRootPart instead of the UpperTorso and see what happens.

0

Still doesn't work

0

What's script.Parent.Parent referring to?

0

The Gui's Parent

3 answers

game.Players.LocalPlayer.PlayerScripts.ControlScript.Disabled = true

2 comments

0

Doesn't work.

0

i'm giving you the way to disable player movement. i'm not scripting it in for you

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.

3 comments

0

That doesn't work too

0

Give more details as to what happens.

0

Is that in script or local script?

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)
	

4 comments

0

That doesn't work too

0

Your using a LocalScript right? You also have to make sure this works for your Gui. When I have the MouseButton1Click event make sure that the code before that is able to locate the button.

0

You also want to make sure that the names for the buttons in the script are the same as in the Gui you are using.

0

If that does not work then I have no idea.

This discussion is preserved as it was. New answers, comments, and votes are closed.