Why is my gamepass tool not working?

I made a tool that is supposed to be given only to the people who bought this gamepass and I realized it wasn’t working after someone bought it (because the game is from a group and I don’t own those gamepasses after creating them).

I don’t know why it’s not working and I’ve been trying to figure it out for some hours. I tried creating a 1 robux testing gamepass and it didn’t work either. I checked other “working” scripts on youtube and the devforum and they don’t seem to have any differences

local MarketplaceService = game:GetService("MarketplaceService")
local hammerid = 28636666

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		if MarketplaceService:UserOwnsGamePassAsync(plr.UserId, hammerid) then
			local hammer = game.ReplicatedStorage.Tools.Hammer:Clone()
			hammer.Parent = plr.Backpack
		end
	end)
end)
2 Likes

I suddenly got it after 15 minutes of being AFK? I don’t know if it’s roblox having issues because the script seems to be half working

Must be your other scripts interfering otherwise, it wouldn’t just give after 15 mins

interfering? like what? removing it? I (guess I) don’t have any other scripts that could be removing the tool

Could it be a roblox issue?

1 Like

Well, are you encountering any lag or errors in the output?

Lag would be caused by various factors including server stress and high quantity of parts (exaggerated by cast-shadow and/or can-collide).

I can’t think of anything else other than script interference. Are you sure it was given to you after simply doing nothing for 15 minutes?

Do some printing, see if anything is delayed or not running.

I can’t tell otherwise, the code should run, and would run instantly for me with no other scripts that could impact performance. I can’t see this being a Roblox issue - for this situation, dumb in and dumb out (check your other scripts). Do you code or does YT do it for you?

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local Replicated = game:GetService("ReplicatedStorage")
local Tools = Replicated.Tools
local Hammer = Tools.Hammer

local GamepassId = 28636666

Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		if MarketplaceService:UserOwnsGamePassAsync(Player.UserId, GamepassId) then
			local HammerClone = Hammer:Clone()
			HammerClone.Parent = Player.Backpack
		end
	end)
end)

This is a server script right? If it is then it should be working fine, it is for me.

1 Like

I just realized it was in the startercharacterscripts instead of serverscriptservice, makes sense now, sorry

1 Like