Answered by
7 years ago Edited 7 years ago
The error is that the first argument of each FireClient
function expects a player, and so Roblox is trying (and failing) to convert the string you've provided into a player. Instead, use FireAllClients
.
Do note that server scripts do not usually have access to a player's GUI. The server should handle purchases, awarding players items, etc, and the client should handle the GUI completely. The client must notify the server when a player wishes to buy something, for instance.
The same script should not have both OnClientEvent
and OnServerEvent
-- either's a server script or a client script, never both (except for the special case when you're testing it in Studio without using the "Start Server" option).
[Edit]
You requested help fixing your scripts, so I did (and uploaded a fixed version here: https://www.roblox.com/library/1114647229/Ki-ngPhantoms-Shop-Fixed
(Note that I only did this because I felt like it -- this site is not a request site. You're supposed to try and make the changes yourself and then ask for help when you don't know how to proceed.)
If you want to get good at scripting, study the scripts and try to understand them (and feel free to ask about them on this site, or even PM me. You can also email me at chess123mate@yahoo.ca. Some topics you'll want to learn about if you want to get better:
- Learn about for loops and tables. Notice how you have the same sort of code over and over again, one for each item? For loops and tables are an important step in solving this.
- Making functions to handle duplicate code is also important. Specifically, whenever you notice you've got the same bit of code in 2+ places, put it in a function instead. Combined with for loops and tables, you can start doing powerful things.
- I invented a "class" called PlayerData. Lua doesn't officially support classes, but there are a number of ways to simulate them. In Roblox there are many classes -- ex,
Part
, Frame
, Trail
, etc. Some important definitions to understand my comments:
private
: Means that the function or variable is not meant to be used outside the class.
public
: Means that the function or variable is meant to be used outside the class.
- It is common to make a variable private but then give public functions for outside code to access it. As I explain in the script, this is beneficial when you want to control how the variable is used -- you can make sure to define the "proper way" to use a variable, rather than allowing outside code to change it however it likes.
- If you want to know more about classes, you might look up "Object Oriented Programming" or "classes in lua".
Other notes about the scripts I've provided:
- I have a whole bunch of functions that do small jobs. The nice thing about this separation is that if you want to change how something is done (ex how you store the price of a trail), you have a single place to change
- Though the script works, there are plenty of TODOs left. If you don't have someone who can help you with it, you'll have to do a bunch of reading (and probably asking). Try to find scripts other people have made and see how they do things -- I know other scripts exist that work with Datastores, for example.
- I'm not sure what you wanted to have happen when the user purchases multiple trails, so I did this:
- If the player doesn't own the trail, they purchase it and then immediately use it
- The player can only use 1 trail at a time. If they attempt to use 2nd one, the 1st one is disabled and then shortly destroyed (giving a really cool effect if you're moving while changing them!)
- If the player attempts to use the same trail they already have, it is cleared instead.