Im trying to get my tool to Unequip when they try to equip it
local tool = script.Parent local player = game:GetService("Players").LocalPlayer local humanoid = player.Character:FindFirstChild("Humanoid") local TurnOn = game.ReplicatedStorage.StorageValues.LaserGunEnabled tool.Equipped:connect(function() if TurnOn.Value == false then -- THE VALUE IS FALSE WHEN GAME STARTED humanoid:UnequipTools() -- unequip the thing. end end)
I used this correctly right?
After testing this for myself, I have concluded that you need to add a wait() to your script.
local tool = script.Parent local player = game:GetService("Players").LocalPlayer local humanoid = player.Character:FindFirstChild("Humanoid") local TurnOn = game.ReplicatedStorage.StorageValues.LaserGunEnabled tool.Equipped:connect(function() if not TurnOn.Value then wait() --magical humanoid:UnequipTools() end end)
local tool = script.Parent local player = game:GetService("Players").LocalPlayer -- this line needs to change, which local player do you think it is going to get? Doesn't work like that you need a new way to get player local char = player.Character or player.CharacterAdded():Wait() local humanoid = char:FindFirstChild("Humanoid") -- this needs to change since above line doesn't work but changed it so it is better local TurnOn = game:GetService('ReplicatedStorage'):WaitForChild('StorageValues').LaserGunEnabled.Value tool.Equipped:Connect(function() if not TurnOn then -- THE VALUE IS FALSE WHEN GAME STARTED humanoid:UnequipTools() -- unequip the thing. end end)
I helped you made some changes to make your script better, it might fix the problem