Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by
Kimuyo 13
8 years ago

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

0
accept my answer, please. Goulstem 8144 — 8y

2 answers

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
8 years ago

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)
0
it works than you Kimuyo 13 — 8y
1
Make sure to check this off as answered, Kim. Xiousa 156 — 8y
Ad
Log in to vote
0
Answered by
Azarth 3141 Moderation Voter Community Moderator
8 years ago

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)

Answer this question