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

Why isn't the TextButton in a ScrollingFrame working?

Asked by
Wutras 294 Moderation Voter
8 years ago
price = 50
local texthandler = coroutine.create(function()
    while wait() do
        script.Parent.Text = "UPGRADE BUILDING [Level: "..script.Parent.Parent.Parent.Selected.Value.Level.Value"]"
    end
end)
script.Parent.MouseButton1Down:connect(function()
    coroutine.resume(texthandler)
    print("Test")
    local level = script.Parent.Parent.Parent.Selected.Value.Level
    if script.Parent.Parent.Parent.Parent.Parent.Gold.Value >= price then
        script.Parent.Parent.Parent.Parent.Parent.Gold.Value = script.Parent.Parent.Parent.Parent.Parent.Gold.Value-price
        price = price*2
        script.Parent.Parent.Parent.Selected.Value.Level.Value = script.Parent.Parent.Parent.Selected.Value.Level.Value+1
    end
end)

I've been making this script to upgrade a building by clicking on a TextButton. I've set several breakpoints and prints(), but it seems to not even start working. The script is enabled and there's no mistake that I can find. So what's wrong? Here's the Explorer: http://prntscr.com/9jucl3

1 answer

Log in to vote
1
Answered by 8 years ago

You will need to change the Script to a LocalScript

Also on line 4,

script.Parent.Text = "UPGRADE BUILDING [Level: "..script.Parent.Parent.Parent.Selected.Value.Level.Value"]"

Should be...

script.Parent.Text = "UPGRADE BUILDING [Level: "..script.Parent.Parent.Parent.Selected.Value.Level.Value.."]"

I also wouldn't recommend having that loop (texthandler) without some way to break it, unless you want it to go on forever? It could lag up the client a bit.

1
I would personally connect that function to the Changed event of the Level value. Spongocardo 1991 — 8y
0
Thanks a lot. I only had to change it to a LocalScript. Wutras 294 — 8y
0
No problem darkelementallord 686 — 8y
Ad

Answer this question