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

How can I make this nearly-finished script work?

Asked by 9 years ago

I want this button to work only if the script's parent's child, "PackTitle", has the text "Peak Performance Pack." Would I put an if statement before it?

if script.Parent.Parent.PackTitle.Text == "Peak Performance Pack" then

And would this be added right after (with another end of course)?

Table1={"262077956","262077680","262077809"}
function onButtonClick1()
    local Picked=Table1[math.random(1,#Table1)]
    script.Parent.Parent.Parent.Parent.NewItemsFrame.Card1.Image ="rbxassetid://"..Picked
end

1 answer

Log in to vote
1
Answered by 9 years ago

That is totally correct; difference is that you said that it was the script's parent's child. Which means:

script.Parent.PackTitle

What you wrote:

script.Parent.Parent.PackTitle

That means it's the script's parent's parent's child.

You also did not call the function when the button is clicked.

Full script:

Table1={"262077956","262077680","262077809"}
local button = script.Parent -- change it to the text button that does this when it's clicked

function onButtonClick1()
    if script.Parent.PackTitle.Text == "Peak Performance Pack" then
        local Picked=Table1[math.random(1,#Table1)]
        script.Parent.Parent.Parent.Parent.NewItemsFrame.Card1.Image ="rbxassetid://"..Picked
    end
end

button.MouseButton1Click:connect(onButtonClick1) -- calling the function when it is clicked

Hope it helps!

0
You're a lifesaver! Thanks for helping me! The script worked! User#4422 0 — 9y
Ad

Answer this question