So I have made a string of code that tells my char to stop a script when I equip a tool then turn the script on when I unequip the tool. Here's my code
local Tool = script.Parent.Parent function onEquippedLocal() script.Parent.Parent.Parent:FindFirstChild("Sprint").Disabled = true end function onUnequippedLocal() script.Parent.Parent.Parent:FindFirstChild("Sprint").Disabled = false end Tool.Equipped:connect(onEquippedLocal) Tool.Unequipped:connect(onUnequippedLocal)
It displays this in the output when I unequip the tool
20:24:07.228 - Players.Zendex32.Backpack.Tool.Main.LocalScript:7: attempt to index a nil value 20:24:07.229 - Stack Begin 20:24:07.229 - Script 'Players.Zendex32.Backpack.Tool.Main.LocalScript', Line 7 20:24:07.230 - Stack End
The bit for disabling the script works, but when you unequip the tool it doesn't turn the script back on. If someone can fix the script for me that would really help!!!!
Edit: I forgot to say this before but I have tried everything, making a local variable or ANY type of variable BUT NOTHING WORKS!!!!
DOUBLE EDIT: I FIXED IT BY MAKING A VARIABLE HERES THE FIXED SCRIPT
local Tool = script.Parent.Parent local Plr = script.Parent.Parent.Parent function onEquippedLocal() Plr:FindFirstChild("Sprint").Disabled = true end function onUnequippedLocal() Plr:FindFirstChild("Sprint").Disabled = false end Tool.Equipped:connect(onEquippedLocal) Tool.Unequipped:connect(onUnequippedLocal)
Feel free to take the script what I did for the tool is put the LocalScript in ANOTHER LocalScript so the Tool isn't so cluttered.
Here is a neat fact about scripts. I saw you used a sprint script so you can sprint when holding the tool.
In order to make the character sprint, you need a SCRIPT. I am assuming you used a LOCALSCRIPT for the tool.
Instead of disabling a script using a local script, just use this NORMAL SCRIPT DIRECTLY in the tool.
script.Parent.Equipped:Connect(function() local Player = script.Parent.Parent:FindFirstChild("Humanoid") if Player.Health then Player.WalkSpeed = 32 end end script.Parent.Unequipped:Connect(function() wait(0.1) local Player = script.Parent.Parent.Character:FindFirstChild("Humanoid") if Player.Health then Player.WalkSpeed = 16 end end
This should do what I assumed you wanted to do.
If you have any questions or errors, comment below!
-TheLastHabanero