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.

7 comments
The error is saying that the sprint script doesn't exist when you disable it. Check if there is any other tool script that might be causing this problem when the tool is equipped.
When the Tool is equipped I am quite sure it is moved from the player's Backpack to their Character. Although I am not sure if your "Equipped function" is run before or after the Tool is moved. But the tool is at different locations when your different functions run.
That is probably why. Post this as an answer.
Nothing works as I have said I have tried everything.
also, I recommend using more variables because those .Parent.Parent.Parent chains are quite messy
I suggest using "WaitForChild" because it cannot find it yet, probably because it hasn't loaded.
@RiskoZoSlovenska You were right! That did fix it.