Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I make this nearly-finished script work?

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

✓ Accepted answer

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!

1 comment

0

You're a lifesaver! Thanks for helping me! The script worked!

This discussion is preserved as it was. New answers, comments, and votes are closed.