Been trying to change the character's speed while holding my tool for while, but can't seem to get it.
Script: https://pastebin.com/38RtEwZL
Thanks
Been trying to change the character's speed while holding my tool for while, but can't seem to get it.
Script: https://pastebin.com/38RtEwZL
Thanks
Okay, so first, lets clean up the variables, Naming them "Thing,Thing2,Thing3" is bad practice.
local Tool = script.Parent
local Player = game.Players.LocalPlayer
local Speed= 23
local DefaultSpeed= 16
local Enabled = false
We are going to place the script inside the tool, make it a local script.
Next we are going to create the equip function:
Tool.Equipped:Connect(function()
if Player and Enabled == false then
Enabled = true
Player.Character.Humanoid.WalkSpeed = Speed
else
if Player then
Enabled = false
Player.Character.Humanoid.WalkSpeed = DefaultSpeed
end
end
end)
Great! That should work! Remember to accept my answer if it helps, and let me know if you have any questions!
It worked wonderfully, but what do you mean by "if Player and"?
That is to check if the player exists, just to not have any bugs if the player for some weird reason doesn't load.
This discussion is preserved as it was. New answers, comments, and votes are closed.
3 comments
Please use scripting helpers built-in code format.
You generally shouldn't put events inside events btw, which is one of the reasons why your code wasn't working.
Yep, that was a reason, but I cleared things up. It is fine in some cases, but this was definitely not one of them.