So, I'm trying to make leaderstats. I've followed a lot of tutorials, this is what i have.
function onPlayerEntered(newPlayer) wait(.5) local stats = Instance.new("IntValue") stats.Name = "leaderstats" local score = Instance.new("IntValue") score.Name = "Money" score.Value = 0 score.Parent = stats stats.Parent = newPlayer end game.Players.ChildAdded:connect(onPlayerEntered)
It doesn't work. How do I make one that works?
This script also will save the currency of your cash, you also have to place this script in the ServerScriptService
local ds = game:GetService("DataStoreService"):GetDataStore("--Cash01") game.Players.PlayerAdded:Connect(function(player) local folder = Instance.new("Folder",player) folder.Name = "leaderstats" local cash = Instance.new("IntValue",folder) cash.Name = "Cash" cash.Value = 20 local key = "cash-"..player.userId local save = ds:GetAsync(key) if save then cash.Value = save end cash.Changed:Connect(function() ds:SetAsync(key,cash.Value) end) end)