Hi cookie tech So I am trying to set up some leaderstats but when someone joins the game the leaderstats are ethier - or people only get one leaderstat and not the other.
How can I make two leaderstats like this? These are the scripts!
Rank:
local GroupID = 5122099 -- Id of group; is found in the URL/link
local CharHide = 0 -- Amount of characters from the beginning of rank name to hide.
-- Useful if role has numbers or HR/LR in it, and you don't want it in game.
game:GetService('Players').PlayerAdded:Connect(function(p)
local ls = Instance.new('IntValue', p)
ls.Name = 'leaderstats'
local rank = Instance.new('StringValue', ls)
rank.Name = 'Rank'
rank.Value = 'Guest'
if p:IsInGroup(GroupID) then
local xrole = p:GetRoleInGroup(GroupID)
if string.len(xrole) <= CharHide then
warn('[GroupLeaderboard] Attempted to hide more characters than role has; using default name')
rank.Value = xrole
else
local role = string.sub(xrole, CharHide+1)
rank.Value = role
end
end
end)
Money:
-- For a documentation on DataStore2, read this: https://devforum.roblox.com/t/how-to-use-datastore2-data-store-caching-and-data-loss-prevention/136317
local ds2 = require(game.ServerScriptService:WaitForChild("DataStore2"))
local defaultValue = script:GetAttribute("DefaultValue")
game.Players.PlayerAdded:Connect(function(plr)
local ds = ds2("MoneySave", plr)
local leader = Instance.new("Folder", plr)
leader.Name = script:GetAttribute("FolderName")
local m = Instance.new("IntValue", leader)
m.Name = script:GetAttribute("CurrencyName")
local updateValue = function(updatedValue)
m.Value = ds:Get(updatedValue)
end
updateValue(defaultValue)
ds:OnUpdate(updateValue)
end)
game.ReplicatedStorage:WaitForChild("RobberyAddValue").Event:Connect(function(plr, value)
local dataStore = ds2("MoneySave", plr)
dataStore:Increment(value, defaultValue)
end)
local GroupID = 5122099 -- Id of group; is found in the URL/link
local CharHide = 0 -- Amount of characters from the beginning of rank name to hide.
-- Useful if role has numbers or HR/LR in it, and you don't want it in game.
game:GetService('Players').PlayerAdded:Connect(function(p)
local ls = Instance.new('IntValue', p)
ls.Name = 'leaderstats'
local rank = Instance.new('StringValue', ls)
rank.Name = 'Rank'
rank.Value = 'Guest'
if p:IsInGroup(GroupID) then
local xrole = p:GetRoleInGroup(GroupID)
if string.len(xrole) <= CharHide then
warn('[GroupLeaderboard] Attempted to hide more characters than role has; using default name')
rank.Value = xrole
else
local role = string.sub(xrole, CharHide+1)
rank.Value = role
-- For a documentation on DataStore2, read this: https://devforum.roblox.com/t/how-to-use-datastore2-data-store-caching-and-data-loss-prevention/136317
local ds2 = require(game.ServerScriptService:WaitForChild("DataStore2"))
local defaultValue = script:GetAttribute("DefaultValue")
game.Players.PlayerAdded:Connect(function(plr)
local ds = ds2("MoneySave", plr)
local leader = Instance.new("Folder", plr)
leader.Name = script:GetAttribute("FolderName")
local m = Instance.new("IntValue", leader)
m.Name = script:GetAttribute("CurrencyName")
local updateValue = function(updatedValue)
m.Value = ds:Get(updatedValue)
end
updateValue(defaultValue)
ds:OnUpdate(updateValue)
end)
game.ReplicatedStorage:WaitForChild("RobberyAddValue").Event:Connect(function(plr, value)
local dataStore = ds2("MoneySave", plr)
dataStore:Increment(value, defaultValue)
end)
end
end
end)
value = Instance.new("IntValue")
value.Parent = workspace.x
-- For a documentation on DataStore2, read this: https://devforum.roblox.com/t/how-to-use-datastore2-data-store-caching-and-data-loss-prevention/136317
local ds2 = require(game.ServerScriptService:WaitForChild("DataStore2"))
local defaultValue = script:GetAttribute("DefaultValue")
game.Players.PlayerAdded:Connect(function(plr)
local ds = ds2("MoneySave", plr)
local leader = Instance.new("Folder", plr)
leader.Name = script:GetAttribute("FolderName")
local m = Instance.new("IntValue", leader)
m.Name = script:GetAttribute("CurrencyName")
local updateValue = function(updatedValue)
m.Value = ds:Get(updatedValue)
end
updateValue(defaultValue)
ds:OnUpdate(updateValue)
end)
game.ReplicatedStorage:WaitForChild("RobberyAddValue").Event:Connect(function(plr, value)
local dataStore = ds2("MoneySave", plr)
dataStore:Increment(value, defaultValue)
end)
value = Instance.new("IntValue")
value.Parent = workspace.x
Something along those lines, but you can’t copy and paste it, you’ll need to customize the parent of the integer to the leaderstats folder in the player.