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

Why wont my Gui Equip/un equip and reequip again? [ No Answer Yet!! ]

Asked by 9 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

``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)
Mod Edit: Added code block - UrbanPatriot

2 answers

Log in to vote
0
Answered by
rexbit 707 Moderation Voter
8 years ago

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.
Ad
Log in to vote
0
Answered by 9 years ago

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.

Answer this question