game.Players.PlayerAdded:connect(function(plr) local money = Instance.new("IntValue", game.Players.LocalPlayer) money.Value = 50 end)
I can't seem to figure out why this isn't working, maybe I need to user leaderstats? But I didn't think that was needed as I just need a singular intvalue to define how much money the user currently has.
Well, here it is hope this helps.
First off, a server script can't access the LocalPlayer
object. Also that's not a good way to go about doing this.
I'm also adding DataStore
for you so it saves it! You're welcome! XD
So do this in a Server script
local startingCashValue = 0 -- Set this to what you want the player to start out with local DataStore = game:GetService("DataStoreService") local ds1 = DataStore:GetDataStore("MoneyDataStore") game.Players.PlayerAdded:connect(function(plr) local leader = Instance.new("Folder") local cash = Instance.new("IntValue") leader.Name = "leaderstats" leader.Parent = plr cash.Name = "Money" cash.Parent = leader cash.Value = ds1:GetAsync(player.UserId) or startingCashValue end) game.Players.PlayerRemoving:connect(function(player) print("Saving Data For "..player.Name.."..") ds1:SetAsync(player.UserId, player.leaderstats.Points.Value) print("Data For "..player.Name.." has been saved!") end)
If this is a normal script you cannot use game.Players.LocalPlayer
But that is okay because when you set up
game.Players.PlayerAdded:connect(function(plr)
you made the parameter plr
you can just do this instead
local money = Instance.new("IntValue", plr) -- use plr here money.Value = 50