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

Issue with buybutton?

Asked by 9 years ago

I keep getting the output '11:37:53.720 - Workspace.Model.Button.Main:25: bad argument #2 to '?' (string expected, got Object) 11:37:53.723 - Script 'Workspace.Model.Button.Main', Line 25 11:37:53.724 - Stack End 11:40:06.226 - Auto-Saving...'.

How can I fix this issue?

local config = script.Parent.Parent.Config
local price = config:WaitForChild("Price")
local itemName = config:WaitForChild("ItemName")                                                                                --[[
-Variables-

-Main Code-                                                                                                                     --]]
script.Parent.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        local plr = game.Players:FindFirstChild(hit.Parent.Name)
        if plr:FindFirstChild("active").Value == false then
            plr:FindFirstChild("active").Value = true
            local plrGui = plr:WaitForChild("PlayerGui")
            local popUp = plrGui:FindFirstChild("PurchasePopup")

            popUp.Frame.P1.Text = "Are you sure you want to buy "..itemName.Value.." for "..price.Value.."pts?"
            popUp.Frame.Visible = true

            local function buy()
                local points = plr:WaitForChild("leaderstats").Points
                local active = plr:WaitForChild("active")
                if points.Value >= price.Value then
                    points.Value = points.Value - price.Value
                    active.Value = false
                    popUp.Frame.Visible = false
                    local tool = game.Lighting[itemName]
                    tool:Clone().Parent = game.Workspace
                end
            end

            local function cancel()
                local active = plr:WaitForChild("active")
                active.Value = false
                popUp.Frame.Visible = false 
            end

            popUp.Frame.Accept.MouseButton1Down:connect(buy)            
            popUp.Frame.Ignore.MouseButton1Down:connect(cancel)         
        end
    end
end)

Answer this question