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
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
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
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.
2 comments
What is the "players" definition? what event is causing the credits value to increase?
idk i am not good at scripting