Shop gear isn't working

I was trying to make a gravity coil that got added to your players backpack if you purchase it. It adds the item to my players backpack, but the script that makes the gravity coil work breaks. I think this is because I need to call on all of the children of the gravity coil tool but i’m not sure how. Can anyone help me?

local player = game.Players.LocalPlayer

local ownsGamepass = game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId,11056094)

if ownsGamepass then

local GravityCoil = game:GetService("ReplicatedStorage"):WaitForChild("GravityCoil"):Clone()

GravityCoil.Parent = player.Backpack

end

Are you using that in a Script or LocalScript?

Local script.

Is that whats breaking it?

Its because you call it on the client. So it doesn’t work since u did it on the client. Do this in a server script

game.Players.PlayerAdded:Connect(function(player)
do checks here
end)

Yes.
Is better to do this way:

-Add a Script in ServerScriptService
-Write this:

game.Players.PlayerAdded:Connect(function(Player)
	local ownsGamepass = game:GetService("MarketplaceService"):UserOwnsGamePassAsync(Player.UserId,11056094)
	Player.CharacterAdded:Connect(function()
		if ownsGamepass then
			local GravityCoil = game:GetService("ReplicatedStorage"):WaitForChild("GravityCoil"):Clone()
			GravityCoil.Parent = player.Backpack
		end
	end)
end)
1 Like

Oh so it had to be a normal script, not local in server script service. Thanks, now it works perfect. :grinning:

No, the script you provided works fine.

I placed it inside the StarterCharacterScripts folder and ran a quick test.

local MarketPlaceService = game:GetService("MarketplaceService")
local GamepassID = ______ -- The Gamepass ID

game.Players.PlayerAdded:Connect(function(player)
 
 if MarketPlaceService:UserOwnsGamePassAsync(player.UserId, GamepassID) then
  
  game.ServerStorage.GravityCoil:Clone().Parent = player:WaitForChild("Backpack")
  game.ServerStorage.GravityCoil:Clone().Parent = player:WaitForChild("StarterGear")
 end
end)

You can even use this script. (Note: Add this script in workspace)
Put the tool in “server storage” and use this script.