Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

The start of my 'Money' system is not working correctly, any help?

Asked by
IcyEvil 260 Moderation Voter
6 years ago
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.

0
what exactly isnt working? PoePoeCannon 519 — 6y

2 answers

Log in to vote
1
Answered by 6 years ago

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)
0
It still seems to not work, it isn't creating the leaderstats or the intvalue. IcyEvil 260 — 6y
0
Hmm, that's odd my script is working on my end.. andyad13 74 — 6y
Ad
Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

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  
1
Also note that the parent argument in Instance.new can cause performance issues. Set the parent separately. (See https://devforum.roblox.com/t/psa-dont-use-instance-new-with-parent-argument/30296) xAtom_ik 574 — 6y
0
I was using a LocalScript but thank you! IcyEvil 260 — 6y

Answer this question