``So here is the problem, Currently The gui lets you equip and item unequip, but if i were to try to equip it again than it dosent work, I will post the script bellow as well as an image of where the script is, its the local script. http://prntscr.com/97pes8
New Problem - Errors - Players.Player.PlayerGui.Shop/System.InventoryTab.Inventory.Item.EquipOrUnequip.LocalScript:10: attempt to index local 'cl' (a nil value)
script
player = game.Players.LocalPlayer player:WaitForChild("leaderstats") Cash = player.leaderstats.Money tool = game.Lighting:findFirstChild("Sword") function Check() local cl = game.ServerStorage:FindFirstChild("Sword") cl:Clone() local player = game:GetService("Players").LocalPlayer local Bought = script.Parent.Parent.HasBought local EquipColor = BrickColor.new("Lime green") local EquipColor2 = EquipColor.Color local Equiped = script.Parent.Parent.IsEquiped local UnequipedColor = BrickColor.new("Really red") local UnequipedColor2 = UnequipedColor.Color local find = player.Backpack:findFirstChild("Sword") if Bought.Text == "False" then cl.Parent = nil script.Parent.HaventBot.Visible = true wait(1) script.Parent.HaventBot.Visible = false elseif Bought.Text == "True" and Equiped.Text == "False" then script.Parent.BackgroundColor3 = EquipColor2 script.Parent.Text = "Unequip" cl.Parent = player.Backpack Equiped.Text = "True" elseif Bought.Text == "True" and Equiped.Text == "True" then script.Parent.BackgroundColor3 = UnequipedColor2 script.Parent.Text = "Equip" player.Backpack:findFirstChild("Sword"):Destroy() Equiped.Text = "False" end end script.Parent.MouseButton1Click:connect(Check)
As many have answered, remove can be used, it's just a deprecated method. The real problem is on line 9, localscripts can not view anything in ServerStorage. Use ReplicatedStorage
instead.
local cl = game.ReplicatedStorage:FindFirstChild("Sword") -- place sword in RS first.
Remove line 48. The Remove()
function sets the object's parent to nil, and you are just resetting its parent to the player's backpack.
On line 32 and 33, you are cloning the tool into the player's backpack. You should set the cloning function inside your Check() function and set the clone's parent later inside your if statements.
For example:
function Check() local cl = game.ServerStorage:FindFirstChild("Sword") cl:Clone() if bought.Text == "False" then cl.Parent = nil else if bought.Text == "True" then cl.Parent = player.Backpack end end
I was too lazy to write you a script that applies to your exact situation, but I hope this helps.
You should also use ServerStorage to store your items rather than Lighting. It is much safer and easier to use.