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

How can I fix this script where if the player equips the tool, their speed will change?

So uhmmm the title speaks for itself. What am I doing wrong?

Tool = script.Parent


Humanoid.WalkSpeed = (16 * 2) --- changes the player speed or velocity
	Sounds.Unsheath:Play()
	ToolEquipped = true
end

function Unequipped()
	if CheckIfAlive() then
		Humanoid.WalkSpeed = 16
	end
	ToolEquipped = false
end

1 answer

✓ Accepted answer

Tool.Equipped will listen for when said tool is equipped. Tool.Unequipped will do the same for unequipped. And you'd also need to specify the humanoid as well. Here's a very basic sample script:

Tool.Equipped:Connect(function() --Will listen for when the player equips the tool then connects to the enclosed function
	local char = Tool.Parent --When a tool is equipped it moves from the backpack to the character model
	char.Humanoid.WalkSpeed = 32 --Sets the walkspeed by finding the humanoid that's under the character
end)

Scripts are not inherently smart and thus, you will need to feed them all the information that they actually need and tell them when and what to listen for.

3 comments

0

There's an error: 21:17:25.589 - Players.Simpletton.Backpack.Shotgun.Scripts.Speed:4: ')' expected (to close '(' at line 1) near ''

0

Ahh, nevermind I just had to set the tool's variable to your script, thanks for your help

0

Oh whoops. Minor parenthesis mistake

This discussion is preserved as it was. New answers, comments, and votes are closed.