My code:
function onEnter(player) local ld = Instance.new("IntValue") ld.Parent = player ld.Name = "leaderstats" local value1 = Instance.new("IntValue") value1.Parent = ld value1.Name = "Points" value1.Value = game.DataStoreService:Get end game.Players.PlayerAdded:connect(onEnter) for i,v in pairs(game.Players:GetChildren()) do -- So that it works in Play Solo. onEnter(v) end
Writing a currency system. Really don't want to make a gui just for "points" but will if need be.
If anyone knows why it won't work, I'd love to know.
Ran in Studio.
You should use this as it creates the stat and saves it. Also, game.DataStoreService:Get
isn't a thing.
local DataStore = game:GetService("DataStoreService") local ds = DataStore:GetDataStore("PointsSave") game.Players.PlayerAdded:connect(function(player) local leader = Instance.new("Folder",player) leader.Name = "leaderstats" local Cash = Instance.new("IntValue",leader) Cash.Name = "Points" --Name of your leaderstat Cash.Value = ds:GetAsync(player.UserId) or 100 --Change to how much points the player will start out with ds:SetAsync(player.UserId, Cash.Value) Cash.Changed:connect(function() ds:SetAsync(player.UserId, Cash.Value) end) end) game.Players.PlayerRemoving:connect(function(player) ds:SetAsync(player.UserId, player.leaderstats.Points.Value) end)
This script should go in the ServerScriptService
.
If this helped, please upvote and accept answer.
Just put .Parent before .Name
local ld = Instance.new("IntValue") ld.Name = "leaderstats" ld.Parent = player
Do that with every other stat too