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

How can you target the player's walkspeed when the tool is uneqquiped?

Asked by 6 years ago
01health = 5
02active = false
03walkSpd = 32
04script.Parent.Equipped:connect(function()
05    active = true
06    script.Parent.Parent.Humanoid.WalkSpeed = walkSpd
07 
08end)
09 
10script.Parent.Unequipped:connect(function()
11    active = false
12    script.Parent.Parent.Humanoid.WalkSpeed = 16 --problem area
13 
14end)
15 
View all 21 lines...

It gives me "Humanoid is not a valid member of Backpack" at line 12. I can't figure out how to manipulate the humanoid of the player when the tool is uneqquiped.

0
When its unequipped it goes back in the backpack, I would recommend going workspace:FindFirstChild(script.Parent.Parent.Parent.Name).Humanoid.WalkSpeed = 16 Odawg566 9 — 6y

2 answers

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

Your getting the player's humanoid by going through the hierarchy, but it runs when the Unequipped event fires. So when the Unequipped event fires, the tool gets removed from the character which then you cant access the humanoid. You'd need to use LocalPlayer to get the player's humanoid if this is a local script, as LocalPlayer is the player that the script is running on.

01local health = 5
02local active = false
03local walkSpd = 32
04local player = game.Players.LocalPlayer
05 
06script.Parent.Equipped:Connect(function()
07    active = true
08    player.Character.Humanoid.WalkSpeed = walkSpd -- accessing the player's character
09end)
10 
11script.Parent.Unequipped:Connect(function()
12    active = false
13    player.Character.Humanoid.WalkSpeed = 16
14end)
15 
16while active do -- you dont need to make a if statment
17    script.Parent.Parent.Humanoid.Health = script.Parent.Parent.Humanoid.Health + health
18    wait(1)
19end
Ad
Log in to vote
0
Answered by 6 years ago

when you equip a tool, it will be added inside player's Character
but when you unequip the tool the parent of it will change to the player's backpack
so the Unequipped Event fires when the tool is already inside your backpack

Certainly this solution isn't the best, but it works

01Character = script.Parent.Parent
02Player = game:GetService("Players"):WaitForChild(Character.Name)
03-- Added Variables Above
04 
05health = 5
06active = false
07walkSpd = 32
08script.Parent.Equipped:connect(function()
09    active = true
10    Character.Humanoid.WalkSpeed = walkSpd
11end)
12 
13script.Parent.Unequipped:connect(function()
14    active = false
15    Character .Humanoid.WalkSpeed = 16 --fixed Area :3
View all 22 lines...

Answer this question