Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago
Edited 6 years ago

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

0
Yay now this title is specific MajinBluee 80 — 6y
0
Is that in script or local script? PlaasBoer 275 — 6y
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). DeceptiveCaster 3761 — 6y
0
I said i'm using it in a script and it's forced to be R15 MajinBluee 80 — 6y
View all comments (5 more)
0
Oh, okay. DeceptiveCaster 3761 — 6y
0
Then try anchoring the HumanoidRootPart instead of the UpperTorso and see what happens. DeceptiveCaster 3761 — 6y
0
Still doesn't work MajinBluee 80 — 6y
0
What's script.Parent.Parent referring to? Dog2puppy 168 — 6y
0
The Gui's Parent MajinBluee 80 — 6y

3 answers

Log in to vote
0
Answered by 6 years ago
game.Players.LocalPlayer.PlayerScripts.ControlScript.Disabled = true
0
Doesn't work. MajinBluee 80 — 6y
0
i'm giving you the way to disable player movement. i'm not scripting it in for you mynamajeff1302 2 — 6y
Ad
Log in to vote
0
Answered by
PlaasBoer 275 Moderation Voter
6 years ago
Edited 6 years ago

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.

0
That doesn't work too MajinBluee 80 — 6y
0
Give more details as to what happens. PlaasBoer 275 — 6y
0
Is that in script or local script? PlaasBoer 275 — 6y
Log in to vote
0
Answered by
zblox164 531 Moderation Voter
6 years ago

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)

0
That doesn't work too MajinBluee 80 — 6y
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. zblox164 531 — 6y
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. zblox164 531 — 6y
0
If that does not work then I have no idea. zblox164 531 — 6y

Answer this question