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

Changing Character Speed when Holding tool?

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

3 comments

0

Please use scripting helpers built-in code format.

0

You generally shouldn't put events inside events btw, which is one of the reasons why your code wasn't working.

0

Yep, that was a reason, but I cleared things up. It is fine in some cases, but this was definitely not one of them.

1 answer

✓ Accepted answer

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!

2 comments

0

It worked wonderfully, but what do you mean by "if Player and"?

0

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.