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

How would I use a function to start a while loop?

Asked by
NecoBoss 194
10 years ago

Okay I want to use a function to fire off this while loop

while true do
    stats.Score.Value = stats.Score.Value + 1
    local str = stats.Score.Value
    local str1 = "Your income: "
    player.PlayerGui.ScreenGui.Frame.TextButton.Text = str1..str
    wait(1) 
end 

2 answers

Log in to vote
0
Answered by
NecoBoss 194
10 years ago

I fixed the script and this works

function onClick()
    while true do
        game.Players.LocalPlayer.leaderstats.Score.Value = game.Players.LocalPlayer.leaderstats.Score.Value + 1
        local str =  game.Players.LocalPlayer.leaderstats.Score.Value
        local str1 = "Your income: "
        game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame.TextButton.Text = str1..str
        wait(1)
    end
end

script.Parent.MouseButton1Click:connect(onClick)
Ad
Log in to vote
-1
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
10 years ago

Oh, then you need an event. I prefer anonymous functions when I do events, but you can do it with a normal function just as easily. I will do a normal function here, since that's what you asked.

function onClick()
    while true do
        stats.Score.Value = stats.Score.Value + 1
        local str = stats.Score.Value
        local str1 = "Your income: "
        player.PlayerGui.ScreenGui.Frame.TextButton.Text = str1..str
        wait(1)
    end
end

script.Parent.MouseButton1Down:connect(onClick)

0
Well, I am trying to make it to where when I click a TextButton it starts a while loop. NecoBoss 194 — 10y
0
I edited it, read it now. Perci1 4988 — 10y

Answer this question