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.

1function OnUnequip()
2    local plr = script.Parent.Parent.Parent --script,tool,backpack,player
3    local hum = plr.Character.Humanoid;
4    hum.WalkSpeed = 16;
5end
6 
7script.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.

01local players = game:GetService('Players')
02local me = players.LocalPlayer
03repeat wait() until me.Character
04local char = me.Character
05local humanoid = char:WaitForChild("Humanoid")
06local tool = script.Parent
07-- If you aren't using a handle, make sure you untick the option in the tools properties
08 
09 
10local minimum_walkspeed = 16
11local max_walkspeed = 100
12 
13 
14local function setWalkspeed(walkspeed)
15    humanoid.WalkSpeed = walkspeed
View all 24 lines...

Answer this question