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

How am I not using UnequipTools() Right?

Asked by 6 years ago

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?

0
Any errors in output? BlackOrange3343 2676 — 6y
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." MusicalDisplay 173 — 6y
0
I didnt understand this MusicalDisplay 173 — 6y
2
Try putting a wait before the UnequipTools(). hiimgoodpack 2009 — 6y

2 answers

Log in to vote
0
Answered by
theCJarmy7 1293 Moderation Voter
6 years ago
Edited 6 years ago

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)
0
Yep this definitely worked.. Thanks lol. MusicalDisplay 173 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
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

0
I need to know what type of script and where it is BlackOrange3343 2676 — 6y

Answer this question