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

How come when I unequip this tool the WalkSpeed isnt set back to 16?

function OnUnequip() script.Parent.Parent.Humanoid.WalkSpeed = 16 end

script.Parent.Unequipped:connect(OnUnequip)

I'm making a tool that when you equip it your walkspeed is set to 100

what I'm having trouble with is when you unequip it the walkspeed doesnt change back to 16

whats wrong with this script? I think it's because the tool is no longer the players child so it cant set the walkspeed to 16, but I don't know how to fix this

I'm a beginner scripter in need of help

1 comment

0

accept my answer, please.

2 answers

✓ Accepted answer

When you unequip the tool, it will be placed back into your Backpack. This is why 'script.Parent.Parent' will never have a Humanoid in it.

You have to reference the Character object, then reference the Humanoid.

function OnUnequip() 
	local plr = script.Parent.Parent.Parent --script,tool,backpack,player
	local hum = plr.Character.Humanoid;
	hum.WalkSpeed = 16;
end

script.Parent.Unequipped:connect(OnUnequip)

2 comments

0

it works than you

1

Make sure to check this off as answered, Kim.

Also, you could just use a LocalScript.


local players = game:GetService('Players')
local me = players.LocalPlayer
repeat wait() until me.Character
local char = me.Character
local humanoid = char:WaitForChild("Humanoid")
local tool = script.Parent
-- If you aren't using a handle, make sure you untick the option in the tools properties


local minimum_walkspeed = 16
local max_walkspeed = 100


local function setWalkspeed(walkspeed)
	humanoid.WalkSpeed = walkspeed
end

tool.Equipped:connect(function()
	setWalkspeed(max_walkspeed)
end)

tool.Unequipped:connect(function()
	setWalkspeed(minimum_walkspeed)
end)

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