Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How am I not using UnequipTools() Right?

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?

4 comments

0

Any errors in output?

0

Yep here: "Something unexpectedly tried to set the parent of LaserGun to Backpack while trying to set the parent of LaserGun. Current parent is Red_Musician."

0

I didnt understand this

2

Try putting a wait before the UnequipTools().

2 answers

✓ Accepted answer

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)

1 comment

0

Yep this definitely worked.. Thanks lol.

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

1 comment

0

I need to know what type of script and where it is

This discussion is preserved as it was. New answers, comments, and votes are closed.