Lately, I have tried to make to make a GUI. It is located in Startergui. By clicking on a text button, it's text changes. Inside the text button is a script that changes the player's speed depending on what text is present. This is the script itself :
function run() if script.Parent.Text == "Dash" then script.Parent.Parent.Parent.Parent.Character.Humanoid.WalkSpeed = 70 script.Parent.Text = "Walk" elseif script.Parent.Text == "Walk" then script.Parent.Parent.Parent.Parent.Character.Humanoid.WalkSpeed = 25 script.Parent.Text = "Dash" end end script.Parent.MouseButton1Click:connect(run)
In others words : If the button reads ''Dash'', you gain a walkspeed of 70 If the button reads ''Walk'', you gain a walkspeed of 25. When clicking said button while Play Testing inside the studio, it works like a charm.
However, when inside a game, clicking the button doesn't affect the player's speed!
I've thought that either the click didn't register, or the script didn't work, but it is most likely the latter. It is not a LocalScript, just a regular script. I haven't tried to come up with a solution, due to lack of knowledge. I would be kind if anyone we're to help me fix this script! It's pretty much a key element in my game!
First off, ALWAYS USE LOCAL SCRIPTS IN GUI!!! :O
When you want a player's GUI to change, you don't want the every other player's GUI to change too right? That's why we use local scripts located in GUI, they only change what's local, on the current player only.
The reason why it worked during play test was because Roblox Studio acts as the server and client(player) and that's why it's not always accurate to play test things.
The solution is fairly simple, just change your script to a Local Script.
However, I also recommend you use variables. This makes it so you don't have to type script.Parent.Parent.Parent.Parent.Parent.Parent
on and on and on every time you want to reference that object.
I hope I helped! :)
Script
s do not run in PlayerGui
. They will run from Play Solo, and in Experimental Mode
. However, with Experimental Mode
being removed, this is no longer the case and Script
s will no longer run from there in a normal server. The fix would be to use a LocalScript
. These in fact do run in PlayerGui
, and these should be used to handle GUI input and any other input.local player = game.Players.LocalPlayer -- only works from localscripts -- avoid using script.Parent.Parent.Parent.Parent.Parent.Parent.Parent local function run() -- use local functions! if script.Parent.Text:lower() == "dash" then -- they could type "DASH", "dAsH", etc player.Character.Humanoid.WalkSpeed = 70 script.Parent.Text = "Walk" elseif script.Parent.Text == "Walk" then player.Character.Humanoid.WalkSpeed = 25 script.Parent.Text = "Dash" end end script.Parent.MouseButton1Click:Connect(run)
RBXScriptSignal:connect()
is deprecated, use RBXScriptSignal:Connect()
instead.