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

There are no errors and ive tested in studio and it doesnt work?

Asked by 4 years ago

it doesnt work , some already fixed the older version of the script.

    local ItemSlot1 = script.Parent.Parent.Parent.ItemSlot1
    local ItemSlot2 = script.Parent.Parent.Parent.ItemSlot2
    local ItemSlot3 = script.Parent.Parent.Parent.ItemSlot3

    local EquipedSlots1 = script.Parent.Parent.Parent.EquipedSlots1
    local EquipedSlots2 = script.Parent.Parent.Parent.EquipedSlots2
    local EquipedSlots3 = script.Parent.Parent.Parent.EquipedSlots3

    script.Parent.MouseButton1Click:Connect(function()
        if ItemSlot1.Value == false then
            script.Parent.Visible = false
            EquipedSlots1.Visible = true
            ItemSlot1.Value = true
    return ;
    end

            if ItemSlot2.Value == false then
                script.Parent.Visible = false
                EquipedSlots2.Visible = true
                ItemSlot2.Value = true
    return ;
    end

                if ItemSlot3.Value == false then
                    script.Parent.Visible = false
                    EquipedSlots3.Visible = true
                    ItemSlot3.Value = true
                    elseif ItemSlot3.Value == true then
                        print("All slots are being used.")
             end

    end)

0
dont use parent spam EmbeddedHorror 299 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

Improvements

Use local variables for all instances which are used more than once as it makes your code easier to read and edit

Use :WaitForChild() to make sure an instance exists before using it (if it doesn't exist, you will see an infinite yield in the Output telling you so)

Use elseif in conjunction with your initial if statement instead of multiple if-then. When the first condition is not met, the next condition will be tested.

Use .Activated() so that your code works for all devices and not just computers.

Potential Issues

Parenting may be incorrect, the WaitForChild will help you determine if this is the case, so you'd need to alter the reference of the local variable

If this is a Server Script, only LocalScripts will work for Text/Image Buttons, so youd need to change the script type.

Issues

In ROBLOX Lua, you do not require a semicolon after the return, (which you'd need for Java).

Revised Local Script

local button = script.Parent
local folder = button.Parent.Parent
local ItemSlot1 = folder:WaitForChild("ItemSlot1")
local ItemSlot2 = folder:WaitForChild("ItemSlot2")
local ItemSlot3 = folder:WaitForChild("ItemSlot3")
local EquipedSlots1 = folder:WaitForChild("EquipedSlots1")
local EquipedSlots2 = folder:WaitForChild("EquipedSlots2")
local EquipedSlots3 = folder:WaitForChild("EquipedSlots3")

button.Activated:Connect(function()
    if ItemSlot1.Value == false then
        button.Visible = false
        EquipedSlots1.Visible = true
        ItemSlot1.Value = true
    elseif ItemSlot2.Value == false then
        button.Visible = false
        EquipedSlots2.Visible = true
        ItemSlot2.Value = true
    elseif ItemSlot3.Value == false then
        button.Visible = false
        EquipedSlots3.Visible = true
        ItemSlot3.Value = true
    else
        print("All slots are being used.")
    end
end)
Ad

Answer this question