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

Script-generated TextButton that makes leaderstat 'Money' go up by one each time not working?

Okay, so first off, here is the script(global script) that creates the leaderboard. It is located in workspace.

game.Players.PlayerAdded:connect(function(player)
    local leaderstats = Instance.new("Model")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player
    local Money = Instance.new("IntValue")
    Money.Name = "Money"
    Money.Value = 0
    Money.Parent = leaderstats
end)

while wait(0.5) do
	for _, player in ipairs(game.Players:GetPlayers()) do
		if player:FindFirstChild("leaderstats") then
			player.leaderstats.Money.Value = player.leaderstats.Money.Value + 1
		end
	end
end

Next, we have the script that is located in StarterGui.

local Player = game.Players.LocalPlayer.PlayerGui

local Gui = Instance.new("ScreenGui")
Gui.Parent = Player
local Button = Instance.new("TextButton")
Button.Parent = Gui
Button.Size = UDim2.new(0,150,0,50)
Button.Position = UDim2.new(0,10,0,400)
Button.BackgroundColor3 = Color3.new(0,0.4,1)
Button.Text = "Click for money!"
Button.BorderSizePixel = 4
Button.TextColor3 = Color3.new(0,0,0)
Button.TextSize = 22
Button.Font = 12
Button.BorderColor3 = Color3.new(0,0,0)

Button.MouseButton1Down:connect(function()
	for _,Player in pairs(game.Players:GetPlayers()) do
	    if Player:FindFirstChild("leaderstats") then
	        Player.leaderstats.Money.Value = Player.leaderstats.Money.Value +1
	end)

For some reason that I do not know, I'm getting the output response "unexpected symbol near ')'" for line 21 of the previous script. The leaderboard works fine, and goes up by 1 every half of a second, it's just the second script that does not. I'm guessing that I'm going to have to tweak each a bit to do so. Thank you in advance for helping me solve this problem. :)

1 answer

✓ Accepted answer

This is definitely your issue.

local Player = game.Players.LocalPlayer.PlayerGui

local Gui = Instance.new("ScreenGui")
Gui.Parent = Player
local Button = Instance.new("TextButton")
Button.Parent = Gui
Button.Size = UDim2.new(0,150,0,50)
Button.Position = UDim2.new(0,10,0,400)
Button.BackgroundColor3 = Color3.new(0,0.4,1)
Button.Text = "Click for money!"
Button.BorderSizePixel = 4
Button.TextColor3 = Color3.new(0,0,0)
Button.TextSize = 22
Button.Font = 12
Button.BorderColor3 = Color3.new(0,0,0)

Button.MouseButton1Down:connect(function()
    for _,Player in pairs(game.Players:GetPlayers()) do
        if Player:FindFirstChild("leaderstats") then
            Player.leaderstats.Money.Value = Player.leaderstats.Money.Value +1
    end)

Here's a fixed version along with an explanation:

local ui = game.Players.LocalPlayer.PlayerGui

local sgui = Instance.new("ScreenGui").Parent = ui
local button = Instance.new("TextButton").Parent = sgui

Button.Size = UDim2.new(0,150,0,50)
Button.Position = UDim2.new(0,10,0,400)
Button.BackgroundColor3 = Color3.new(0,0.4,1)
Button.Text = "Click for money!"
Button.BorderSizePixel = 4
Button.TextColor3 = Color3.new(0,0,0)
Button.TextSize = 22
Button.Font = 12
Button.BorderColor3 = Color3.new(0,0,0)

Button.MouseButton1Down:connect(function()
    for _,Player in pairs(game.Players:GetPlayers()) do
        if Player:FindFirstChild("leaderstats") then
            Player.leaderstats.Money.Value = Player.leaderstats.Money.Value +1
	end --mistake one
    end --mistake two
end)

You forgot to add two ends, noted by the comments. All functions require an end, you forgot to add one for the if statement & the for loop.

ps: I made the script a bit cleaner, less lines woo~

2 comments

0

Okay wow thank you so much. I don't know how I overlooked the missing ends, but it works perfectly after adding two. Thank you!

0

No problem. :-)

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