MarketPlaceService and ReplicatedStorage not working?

I am using a Script to check if the player has a gamepass, and if it has, clone an item into it’s backpack. However, when someone who doesn’t own the gamepass joins, it gives the error -- "bad sword" was not found. And when someone who does have it joins, the script breaks. The script is a part of a script in a PlayerGui. I’ve tried to mess around with the code, but I can’t figure out why it acts like this. Here’s the script:

local ownPass = false

local succ, message = pcall(function()
	local mps = game:GetService("MarketplaceService")
	ownPass = mps:UserOwnsGamePassAsync(Player.UserId, 98967388)

if ownPass == true then
	local sword = rp:FindFirstChild("Bad Sword")
	sword:Clone().Parent = Player.Backpack

Do you know why this happens? Help greatly appretiated!

1 Like

Are you doing this on the Client?

Use :WaitForChild() to check as it takes a bit of time for the Assets to Load on the Client


No, this is on the server, but I’ll try to do make it wait.

Could you show errors that your script makes when you own and don’t own the gamepass?

I did this and now the error message stops comming, but the rest of the script still breaks for the person with the gamepass

The errors dissapeared when I swapped :FindFirstChild with :WaitForChild but the script still does’nt work. The only error that existed was -- "bad sword" was not found

Might be good to mention that this is triggered uppon a TextButton click

Edit: oops, I meant to reply to the post not this comment

Where did you get this error from? :FindFirstChild() doesn’t throw errors, it just returns nil?

What do you mean it breaks? Do you get an attempt to index nil with 'Clone' error or something else?

I don’t think server side scripts should be under PlayerGui.

Okay, so I solved this. I’m not quite sure, but the problem might have been that I was for some reason inable reach ReplicatedStorage from PlayerGui. That’s weird, as it should be possible and I do exactly that earlier in the script.

The solution was to put the sword in the script instead of in ReplicatedStorage

This is the really scuffed part, it just threw that out in the console - no source or red error text.

I don’t get any error from what I can see, it just stops functioning.

It’s a character selection gui, so it has to be server-sided to change the players character. Why don’t you think so?

It must come from somewhere, maybe show more code? Unless you’re satisfied with the current solution.

Are there any other scripts that interact with this script? Or maybe somewhere earlier in this script the code stops, so that this part is never reached.

Because everything under PlayerGui will be copied per player, which is very odd to do on a script that isn’t for a specific player.

1 Like

Well, I don’t think there are any other scripts interacting with it, but there might be. It’s also weird that it wouldn’t work from adding those lines of code, it worked perfectly fine before.

I’m on my phone right now, but I’ll check it when I get back home. I can also send the whole script then, but it’s kinda messy, so I’ll have to clean it up first :person_facepalming:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.