The goal that I want to achieve with this is to have a car spawner that will take your money away when you purchase a car.
The issue is that when I purchase a car, the money used to purchase said car does not decrease on the leaderstats. Lets say I have $100,000 and the car I want is $70,000. If I were to purchase that car, my initial money doesn’t decrease at all.
I have tried to rework the leaderstat positions and names, as well as the setup of how it’s scripted. Nothing I’m trying is working.
So if I were to replace “plrMoney” with something like
“ourPlayer.leaderstats.Money.Value = ourPlayer.leaderstats.Money.Value - price”
I would think that would help my problem. But the problem continues. This is the first time I’ve ever gotten into datastore scripting and stuff, so I’m honestly clueless with all of this
Is this run in a LocalScript? Because then the changes won’t replicate to the server. If it’s ran in a Script, then you won’t be able to access LocalPlayer because it’s nil on the server.
His suggestion gave me the red-line. I’m honestly not sure what is wrong with this script.
Would I need to completely remove this line? Is there anything I could replace it with?
local ourPlayer = game.Players.LocalPlayer
Like I was saying before, this is my first time working with types of scripts like this. I’m not the most educated in this area.
Sorry, I’m absolutely clueless
Don’t worry, scripting is kinda hard to learn. FireServer() automatically passes over the Player instance that uses it, which you have already acknowledged and specified as “plr”. Simply replace “Player” with “plr” and you’re good to go.
Alright, so I just ran a couple tests. I added a few more areas in the script where it’ll print a message. Where it says print("Pre-Buy"), that is the last line that is run before there’s an error. The error occurs with the if-statement on leaderstats
So with this system, theres a few different scripts. There’s a script in serverscriptservice, and that’s the one that I’ve been working on with the whole plr vs player and localplayer topic. Theres a module script within a GUI in a clickpart, and thats where the veh[number]'s are.
Alright so, I tried purchasing two cars. One car was worth $0, and the other was worth $20,000. The free car purchased perfectly fine, and saved to my player. The $20,000 dollar car did not purchase, and did not save to my player.
Here’s a screenshot of the output:
At the bottom, where it says “20000”, that’s the print of print(price) (price = veh[6])