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

Function doesn't run ONLY on the second time it's called?

Asked by 9 years ago

Hi all, I'm having some problems with a shop/item selection GUI. The script below is supposed to interface between ALL the items that the player has available and a "hotbar" for the 5 items the player wants to have at his/her fingertips. The items have to be handled by storing the info relevant to it (spawn name, image, description, name that player sees, etc.) inside the GUI button for it, so this script adds all said info an available hotbar button. The problem is that the SECOND item added to the hotbar is never usable. The button shows up in the GUI, but clicking it doesn't connect the other script. Is the problem somewhere here and I'm just missing it?

local GUI = script.Parent.Parent.Parent
local hed = script.Parent.Parent:WaitForChild("Header")
local frm = script.Parent.Parent:WaitForChild("SelectFrame")---------------------- this gui frame
---------------------- The frame getting affected by this script:
local back = script.Parent.Parent:WaitForChild("Col1P")
local cl2 = script.Parent.Parent:WaitForChild("Col2")
local player = game.Players.LocalPlayer
---------------------- all the buttons in this gui frame
local b1 = frm:WaitForChild("Main"):WaitForChild("B1")
local b2 = frm.Main:WaitForChild("B2")
local b3 = frm.Main:WaitForChild("B3")
local b4 = frm.Main:WaitForChild("B4")
local b5 = frm.Main:WaitForChild("B5")
local b6 = frm.Main:WaitForChild("B6")
local b7 = frm.Main:WaitForChild("B7")
local b8 = frm.Main:WaitForChild("B8")
local b9 = frm.Main:WaitForChild("B9")
local b10 = frm.Main:WaitForChild("B10")
local b11 = frm.Main:WaitForChild("B11")
local b12 = frm.Main:WaitForChild("B12")


---------------------- Extra functions used by the main one
function startup()
    wait(3)
    script.Parent:WaitForChild("Loader").Disabled = false
    wait(1)
end
function Exit()
    GUI.Parent.Click:Play()
    frm.Visible = false
    back.Visible = true
end
function play()
    player.Backpack.Blip:Play()
end
function mouseEnt(ftitle, fimg, fdesc)
    player.Backpack.Blip:Play()
    cl2.TextLabel.Text = fdesc
    cl2.Title.Text = ftitle
    cl2.IMG.Image = fimg
end

---------------------- This function is where the problem seems to be
function mouseClk(button, btitle, bimg, bname, bdesc)
    player.Backpack.Blip:Play()

    ---------------------- If it's an active button, the deactivate
    if button.Style == Enum.ButtonStyle.RobloxRoundDefaultButton then
        local done = false

        for i = 1, 5 do --change to inactive
            local v = back:FindFirstChild("B"..i) ---------------------- is the current of 5 buttons open?

            ---------------------- found open button to use? Then load the info to it
            if done == false and v:IsA("TextButton") and v.Text == btitle then
                v.Text = ""
                v.fTitle.Value = ""
                v.fName.Value = ""
                v.fImg.Value = ""
                v.fDesc.Value = ""
                v.Visible = false
                button.Style = Enum.ButtonStyle.RobloxButton
                done = true
            end
        end
        if player.ActiveFighters:FindFirstChild(bname) then
            player.ActiveFighters:FindFirstChild(bname):Destroy()
        end
    else ---------------------- Otherwise activate the button
        local done = false

        for i = 1, 5 do --change to active
            local v = back:FindFirstChild("B"..i)

            ---------------------- Clear the info from the button to avoid errors for next time it is used
            if done == false and v:IsA("TextButton") and v.Visible == false then
                v.Text = btitle
                v.fTitle.Value = btitle
                v.fName.Value = bname
                v.fImg.Value = bimg
                v.fDesc.Value = bdesc
                v.Visible = true
                button.Style = Enum.ButtonStyle.RobloxRoundDefaultButton
                done = true
            end
        end
        if not player.ActiveFighters:FindFirstChild(bname) then
            local copy = player.Inventory:FindFirstChild(bname):Clone()

            copy.Parent = player.ActiveFighters
        end
    end
end

---------------------- run "loading" function
startup()
---------------------- To exit the GUI
frm.Exit.MouseEnter:connect(play)
frm.Exit.MouseButton1Click:connect(Exit)

---------------------- Mouse hover connectors
b1.MouseEnter:connect(function() mouseEnt(b1.fTitle.Value, b1.fImg.Value, b1.fDesc.Value) end)
b2.MouseEnter:connect(function() mouseEnt(b2.fTitle.Value, b2.fImg.Value, b2.fDesc.Value) end)
b3.MouseEnter:connect(function() mouseEnt(b3.fTitle.Value, b3.fImg.Value, b3.fDesc.Value) end)
b4.MouseEnter:connect(function() mouseEnt(b4.fTitle.Value, b4.fImg.Value, b4.fDesc.Value) end)
b5.MouseEnter:connect(function() mouseEnt(b5.fTitle.Value, b5.fImg.Value, b5.fDesc.Value) end)
b6.MouseEnter:connect(function() mouseEnt(b6.fTitle.Value, b6.fImg.Value, b6.fDesc.Value) end)
b7.MouseEnter:connect(function() mouseEnt(b7.fTitle.Value, b7.fImg.Value, b7.fDesc.Value) end)
b8.MouseEnter:connect(function() mouseEnt(b8.fTitle.Value, b8.fImg.Value, b8.fDesc.Value) end)
b9.MouseEnter:connect(function() mouseEnt(b9.fTitle.Value, b9.fImg.Value, b9.fDesc.Value) end)
b10.MouseEnter:connect(function() mouseEnt(b10.fTitle.Value, b10.fImg.Value, b10.fDesc.Value) end)

---------------------- connectors
b1.MouseButton1Click:connect(function() mouseClk(b1, b1.fTitle.Value, b1.fImg.Value, b1.fName.Value, b1.fDesc.Value) end)
b2.MouseButton1Click:connect(function() mouseClk(b2, b2.fTitle.Value, b2.fImg.Value, b2.fName.Value, b2.fDesc.Value) end)
b3.MouseButton1Click:connect(function() mouseClk(b3, b3.fTitle.Value, b3.fImg.Value, b3.fName.Value, b3.fDesc.Value) end)
b4.MouseButton1Click:connect(function() mouseClk(b4, b4.fTitle.Value, b4.fImg.Value, b4.fName.Value, b4.fDesc.Value) end)
b5.MouseButton1Click:connect(function() mouseClk(b5, b5.fTitle.Value, b5.fImg.Value, b5.fName.Value, b5.fDesc.Value) end)
b6.MouseButton1Click:connect(function() mouseClk(b6, b6.fTitle.Value, b6.fImg.Value, b6.fName.Value, b6.fDesc.Value) end)
b7.MouseButton1Click:connect(function() mouseClk(b7, b7.fTitle.Value, b7.fImg.Value, b7.fName.Value, b7.fDesc.Value) end)
b8.MouseButton1Click:connect(function() mouseClk(b8, b8.fTitle.Value, b8.fImg.Value, b8.fName.Value, b8.fDesc.Value) end)
b9.MouseButton1Click:connect(function() mouseClk(b9, b9.fTitle.Value, b9.fImg.Value, b9.fName.Value, b9.fDesc.Value) end)
b10.MouseButton1Click:connect(function() mouseClk(b10, b10.fTitle.Value, b10.fImg.Value, b10.fName.Value, b10.fDesc.Value) end)

If you don't understand what it's trying to do, you can see the whole GUI and this script in action here, just go to the hanger and try to spawn a vehicle at the spawn pad: http://www.roblox.com/games/242778663/BF-Space-5k-Update-Test

0
I will try to read this when I have the time...This is a rather long script... lightpower26 399 — 9y
0
Heheh, sorry. I did label the one function that I think would be causing the problem. Thanks. deaththerapy 60 — 9y

Answer this question