I’ve had a gui in my game for as long as I can remember that allows players to purchase a game pass in order to get a glider, and then puts that glider into their starter pack if they bought it. It worked fine forever and then recently it just stopped working. I haven’t made any updated to the game at all, the script just stopped working.
The asset stills exists and the glider is still in lighting where it should be. Does anyone know whats wrong? The script for the GUI is as follows:
local plr = game.Players.LocalPlayer
PlayersAllowed = {"Matthew_James"}
function GiveGlider(plr)
local glider = game.Lighting:findFirstChild’Glider’:Clone()
glider.Parent = plr.StarterGear
glider:clone().Parent = plr.Backpack
end
function check()
if game:GetService("MarketplaceService"):PlayerOwnsAsset(plr,268810058) then
script.Parent.Parent:Destroy()
if not plr.StarterGear:FindFirstChild("Glider") then
Whilst your problem is indeed caused by experimental mode being disabled and the client being unable to create objects to put into starterpack, I recommend in the future to put your code in code headings, which can be done by putting “```Lua” alone on a new line before the code, and putting “```” after.
StarterGear is now only available from the server. I recall a thread I replied in somewhat recently having the same issue and finding out it has been removed from view on the client. You will need to use a server script. Converting the script from a LocalScript to a normal Script and assigning the player the tool on join would still work as long as its done from the server.
Adding on to @cloakedyoshi’s reply, an update was made back in late July that removed Experimental Mode. Even if you untick the FilteringEnabled property it will not do anything.
Now, more along the lines of the spirit of your inquiry, and as already suggested by others, use remotes. I will specifically use a remote event as nothing really needs to be sent back.
-- # Assuming your game has some RemoteEvent named 'giveGlider' in ReplicatedStorage. Feel free to rename it.
-- # Server
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local giveGlider = ReplicatedStorage.giveGlider
local glider -- # the glider
giveGlider.OnServerEvent:Connect(function(client, request)
end)
remoteEvent.OnServerEvent is an event that is listened for on the server side. LocalScripts can call remoteEvent:FireServer(arguments) to fire remoteEvent.OnServerEvent, passing the arguments you put in between the parenthesis to the server. The event listener (on the server side) gets a default first parameter. That is the player that fired the remote event. Everything else after that default parameter is what the client sends.
giveGlider.OnServerEvent:Connect(function(client, request)
if request == "glider" then -- # if they request a glider
glider:Clone().Parent = client.Backpack
glider:Clone().Parent = client.StarterGear
end
end)
And from your local script you would call giveGlider:FireServer("glider"). You do not have to worry about any default arguments when calling remoteEvent:FireServer(arguments).
Of course I will leave everything else such as checking if they already own the glider, to you.
Suggestions
Do not use Lighting for storage.
Lighting is not intended for storage. Use ServerStorage and ReplicatedStorage instead, that’s what they are for. Storage.
Stay consistent.
In some areas you are using local variables, and in others you use global variables. You should always be using local variables. Global variables make your codebase a mess. There are more reasons to avoid global variables but I will not explain any further as it is out of the scope of this answer.
Hopefully this answered your question, and if it did, then don’t forget to mark it as the solution. If you have any other questions then feel free to reply.
@Matthew_James It would be much easier to help if you could edit and change the script, not just keep it in mind in the future.
```lua
print(“Hello”)
```
print("Hello")
You can also show the actual text to be input - as I showed above - by putting a \ (this isn’t the normal slash) before ```lua and ``` to escape it’s formatting.
Please put your code in code blocks next time, so that it’s easier to read. Not going to parrot the rest of the message, because at least 5 people (needlessly) have pointed that out now.
For your code, some practice-related manners which may also lead you into the solution:
Do not use Lighting as a storage for tools, this is an antiquated method of storage. ReplicatedStorage and ServerStorage were created vice the usage of Lighting as tool storage.
Use UserIds when you’re addressing specialised permissions as opposed to usernames. The moment you decide to change your username, you have to go back and edit all your code.
Use UserOwnsGamePassAsync for checking the ownership of game passes, not PlayerOwnsAsset
You seem to be doing this from the client. Don’t. Put this on the server. Have the client pass input and the server do the validation and tool assignment.
You started a loop after the PromptPurchase method, which doesn’t seem to break. An endless-running loop without stopping once it is no longer necessary is not a good idea.
If you are having issues with purchasable items, set them off sale and stop prompting them to purchase it, rather than leaving your items up. If you experience purchase issues and people’s money has been lost due to developer-created errors, try finding a way to compensate them (unless the sum is relatively small, which then just offer an apology for the inconvenience).
Use local variables in your code. Don’t use globals, you have virtually no reason to.
Primarily, it seems that the client is no longer able to access StarterGear. You’ll have to, one way or another, port part or all of this to the server.