The script is used for a GUI. When a player clicks on the GUI button, if they do not have the tool in their backpack it will give them the tool. If they already have the tool, then it will remove the tool. Right now, the script will give me the tool, but if I click again it won't removing it.
However, if I put the tool in the StarterPack and run the script, it removes the tool. It just doesn't give it back again upon a second click. So the remove tool function works, however it doesn't seem to want to work together, or want to work after each other.
local plr = game.Players.LocalPlayer local tools = plr.Backpack Player=script.Parent.Parent.Parent.Parent function ToolRemove() if tools:findFirstChild("Tool") then tools.Tool:Remove() script.Parent.Selected=true wait(.1) end end function ToolAdd() if game.Lighting:findFirstChild("Tool") then Tool=game.Lighting.Tool:clone() Tool.Parent=Player.Backpack script.Parent.Selected=true wait(.1) end end script.Parent.MouseButton1Down:connect(function() if script.Parent.Selected==false then ToolRemove() ToolAdd() end end)
Thank you very much!
Here is a corrected script, you were really close! Your problem was mainly the MouseButton1Down function.
Remove() is deprecated, use Destroy()
local plr = game.Players.LocalPlayer local tools = plr.Backpack local Tool = game.Lighting.Tool Player=script.Parent.Parent.Parent.Parent function ToolRemove() if tools:FindFirstChild("Tool") then tools.Tool:Destroy() wait(.1) end end function ToolAdd() if game.Lighting:FindFirstChild("Tool") then Tool=game.Lighting.Tool:clone() Tool.Parent=Player.Backpack wait(.1) end end script.Parent.MouseButton1Down:connect(function() if Player.Backpack:FindFirstChild("Tool") then ToolRemove() else ToolAdd() end end)