I am working on a game and I have added this pet, and when the button to buy it is clicked, I want the walkspeed of the player to be set higher to give the impression that the pet is given the person a power of walking faster.
How to I make a button that changes the player's walkspeed when clicked?
3 answers
What you need: Local script / Normal script / Remote Event / GUI
In The frame put the local script and a button Edit the button name in the local script provided below
put in local script:
script.Parent.Button.MouseButton1Click:Connect(function() -- Edit button to your buttons Name
game.ReplicatedStorage.ChangeWalkSpeed:FireServer(50)
end)
Create a remote event and name it "ChangeWalkSpeed" and put it in ReplicatedStorage
Create a script and put it in ServerScriptService and add this code:
game.ReplicatedStorage.ChangeWalkSpeed.OnServerEvent:Connect(function(player, Speed)
player.Character.Humanoid.WalkSpeed = tonumber(Speed)
end)
Tell me if it works!
Edit: Had two errors in local script just fixed
4 comments
sorry but it dosent work :( I have been trying for 2 days now and im running out of ideas. I am making a pet sim sort of game but I cant get past the pet shop part.
that works fine for me? what errors you got
https://gyazo.com/8c7daab06fb52d1455c8ca795407b882 That is what it should look like
oh i see i didnt insert the frame
In local script (That's in the Button)
local Speed = 0 -- change this to the number of speed you want
script.Parent.MouseButton1Click:Connect(function()
game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = (Speed)
end)
Haven't tested so idk if it'll work
Also if your making when you equip a pet, you should have it to when the pet is equipped it'll have a passive boost of speed. (To prevent people from getting speed by just clicking the button)
6 comments
enderdragonkk38 thanks so much, it works.
Do you know what ill have to change for it to change other values such as Jump?
yeah just change WalkSpeed to JumpPower and make it over 50 if u want to jump higher or lower if u want to jump less. Also click accept answer on this answer so other people can see how to do this.
also click "Accept Answer" so it can help other people that need it.
That's the same script I just did....
no u messed yours up
If it is a local script, here is what you do:
local button = script.Parent
button.MouseButton1Click:connect:(function()
game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = (Your speed)
end)
Accept answer if I was useful! Any questions? Add me! MedMike#2018
2 comments
hello fortesss7, unfortunatley your script didnt work. sorry
It didn't work because he didn't use a remote event. Poor answer
This discussion is preserved as it was. New answers, comments, and votes are closed.

3 comments
Is it local script or script?
WalkSpeed should not be changed locally.
its a local script#