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
7 years ago
1game.Players.PlayerAdded:connect(function(plr)
2local money = Instance.new("IntValue", game.Players.LocalPlayer)
3money.Value = 50   
4end)

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 — 7y

2 answers

Log in to vote
1
Answered by 7 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

01local startingCashValue = 0 -- Set this to what you want the player to start out with
02 
03local DataStore = game:GetService("DataStoreService")
04local ds1 = DataStore:GetDataStore("MoneyDataStore")
05game.Players.PlayerAdded:connect(function(plr)
06 
07local leader = Instance.new("Folder")
08 
09local cash = Instance.new("IntValue")
10 
11leader.Name = "leaderstats"
12leader.Parent = plr
13 
14cash.Name = "Money"
15cash.Parent = leader
View all 27 lines...
0
It still seems to not work, it isn't creating the leaderstats or the intvalue. IcyEvil 260 — 7y
0
Hmm, that's odd my script is working on my end.. andyad13 74 — 7y
Ad
Log in to vote
1
Answered by 7 years ago
Edited 7 years ago

If this is a normal script you cannot use game.Players.LocalPlayer

But that is okay because when you set up

1game.Players.PlayerAdded:connect(function(plr)

you made the parameter plr

you can just do this instead

1local money = Instance.new("IntValue", plr) -- use plr here
2money.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 — 7y
0
I was using a LocalScript but thank you! IcyEvil 260 — 7y

Answer this question