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

When you click the gui, it will change the leaderstats by 1?

It doesn't show the leaderstats.


local Players = game:GetService("Players")

local function leaderboardSetup(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local Pain = Instance.new("IntValue")
	Pain.Name = "Pain"
	if Pain ~= 0 then
		Pain = Pain + 1
		else
		Pain.Value = 0
		end
	Pain.Parent = leaderstats
	end
Players.PlayerAdded:Connect(leaderboardSetup)

local ClickDetector = Instance.new("ClickDetector")
ClickDetector.MouseClick:Connect(function()
	spawn(leaderboardSetup)
end)

1 answer

You don't parent the ClickDetector to anything. You don't want LeaderboardSetup to run more than once for every player because it will probably mess up the leaderboard, so you should have a separate script to set up the leaderboard when a player joins and a script in your button to change the leaderstats value

local Players = game:GetService("Players")

local function leaderboardSetup(player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    local Pain = Instance.new("IntValue")
    Pain.Name = "Pain"
    Pain.Value = 0
    Pain.Parent = leaderstats
end
Players.PlayerAdded:Connect(leaderboardSetup)

Button script:

-- it would be simpler to just create the ClickDetector in studio but this is how you would create it through a script
local ClickDetector = Instance.new("ClickDetector")
ClickDetector.Parent = script.Parent -- you need to set the parent of it to the button

ClickDetector.MouseClick:Connect(function(player)
    player.leaderstats.Pain.Value = player.leaderstats.Pain.Value + 1
end)

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