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

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

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

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)

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)

2 comments

0

Well, I am trying to make it to where when I click a TextButton it starts a while loop.

0

I edited it, read it now.

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