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

hello i need help with this leaderboard stat giver...Help?

yes hello i am working on a game nd this is kinda my first time with leaderboards

Players.leaderstats.Credits.Value = Players.leaderstats.Credits.Value + 1

i am trying to make it so it would give more Credit(s) on the leaderboard

2 comments

0

What is the "players" definition? what event is causing the credits value to increase?

0

idk i am not good at scripting

1 answer

✓ Accepted answer

So firstly, let's review creating a leaderstats board:

game:GetService("Players").PlayerAdded:Connect(function(player)
	local data = Instance.new("Folder")
	data.Name = "leaderstats"
	data.Parent = player

	local credit = Instance.new("IntValue")
	credit.Name = "Credits"
	credit.Value = 0
	credit.Parent = data
end)

Now to change the value, I'll use a .Touched event in my example

local part = workspace:WaitForChild("AddCredit")
local debounce = true

part.Touched:Connect(function(hit)
	if hit and hit.Parent and game:GetService("Players"):GetPlayerFromCharacter(hit.Parent) and debounce == true then
	debounce = false
	local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
	local credit = player:WaitForChild("leaderstats"):WaitForChild("Credits")
	credit.Value = credit.Value + 1
	wait(1)
	debounce = true
	end
end)

I use WaitForChild() to make sure the parts I'm using exist

GetPlayerFromCharacter() checks that the part's parent is the player's character

The debounce is to prevent the event from being spammed

1 comment

0

14:15:09.916 - Infinite yield possible on 'Workspace:WaitForChild("AddCredit")'

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