Answered by
7 years ago Edited 7 years ago
Make sure you read/understand this: https://scriptinghelpers.org/guides/server-client-relationship-in-roblox
The problem is that your car-giver script is trying to do both server-related activities (generating a car, which you want everyone to be able to see/interact with) and client-related activities (GUI, which you only want to show up for one player). The GUI events aren't even replicated from the client to the server, which is why those MouseButton events aren't firing. You need to move all that GUI code into a LocalScript and then let the server know when the player has requested the purchase of a vehicle using either a RemoteEvent or a RemoteFunction.
Most of your code will either be in one script or another, but when it comes to making sure the player has enough money, you ideally check it in both. The server should check it because you should never trust the client (an exploiter can activate RemoteEvents/Functions with any arguments they want), and you the client should check it to prevent unnecessary communication with the server and lag time (why ask the server to check if the player can afford it, which may take half second, when they could be notified immediately if the client checks first?)
[Edit - Response to comments]
Either Remote Function or event? Is one more preferable?
You can read up on the differences in the API for RemoteEvents and RemoteFunctions, but the essentially you use an Event when you want 1-way communication (ex server telling client that they've been given something) and a Function when you want 2-way (ex client asking server to purchase a vehicle - the server could then respond with whether the purchase was successful)
Like what script do I put in the Remote event/function and how do I fire it
You can put them anywhere you want (except in client-only and server-only areas, like ServerStorage, in a player's GUI, etc), just keep it organized. Putting them in ReplicatedStorage, possibly in a folder, or as a child of the script that handles them are perfectly reasonable. To fire it, you should look at the links above - the API tells you what functions are available. Also, for examples, they have this tutorial: http://wiki.roblox.com/index.php?title=Remote_Events_and_Functions