Gamepass Function won't Run

Hey there,

This isn’t putting the bomb in my backpack. I isn’t even printing ‘test’ which is making me wonder if somethings wrong with the function in the first place :confused:.

(Its the givePlayerBomb that’s acting up).

local Market = game:GetService('MarketplaceService')
local gamePassId = 18500303

-- give player da bomb
local function givePlayerBomb(player)
	
	local function addBomb(character)
		wait()
		local bomb = game.ReplicatedStorage.ClassicTimebomb:Clone()
		bomb.Parent = character.Backpack
		print('test')
	end
	player.CharacterAdded:Connect(addBomb)
	
end

local function newPlayer(player)
	
	local hasPass = false
	
	-- check if player has the gamepass (bomb)
	local success, message = pcall(function() 
		hasPass = Market:UserOwnsGamePassAsync(player.UserId, gamePassId)
	end)
	
	-- warn and stop function if something goes wrong
	if not success then
		warn(message)
		return
	end
	
	-- if player own pass (bomb)
	if hasPass then
		givePlayerBomb(player)
	end
	
end
game.Players.PlayerAdded:Connect(newPlayer)

I appreciate any and all help. If you need any more information, just let me know :slight_smile:

The uh, Character Model does not have the Backpack Instance

You’d need to refer to the Player Object instead:

local Market = game:GetService('MarketplaceService')
local gamePassId = 18500303

-- give player da bomb
local function givePlayerBomb(player)
	
	local function addBomb(character)
		wait()
		local bomb = game.ReplicatedStorage.ClassicTimebomb:Clone()
		bomb.Parent = player.Backpack
		print('test')
	end
	player.CharacterAdded:Connect(addBomb)
	
end

local function newPlayer(player)
	
	local hasPass = false
	
	-- check if player has the gamepass (bomb)
	local success, message = pcall(function() 
		hasPass = Market:UserOwnsGamePassAsync(player.UserId, gamePassId)
	end)
	
	-- warn and stop function if something goes wrong
	if not success then
		warn(message)
		return
	end
	
	-- if player own pass (bomb)
	if hasPass then
		givePlayerBomb(player)
	end
	
end
game.Players.PlayerAdded:Connect(newPlayer)
1 Like

It seems like you’re actually adding the bomb when a Character is added, but it might already exist.
Go into play test and respawn, then see if it prints your message,

Good catch, but it still doesn’t work…

Is the Bomb supposed to be a Tool? Another thing you can try is just cloning the Bomb to the Player’s StarterGear instead so that you don’t have to keep cloning it every time, it’s parented in that specific Player’s Backpack whenever they respawn

local Market = game:GetService('MarketplaceService')
local gamePassId = 18500303

-- give player da bomb
local function givePlayerBomb(player)
	local bomb = game.ReplicatedStorage.ClassicTimeBomb:Clone()
    bomb.Parent = player.StarterGear
end

local function newPlayer(player)
	
	local hasPass = false
	
	-- check if player has the gamepass (bomb)
	local success, message = pcall(function() 
		hasPass = Market:UserOwnsGamePassAsync(player.UserId, gamePassId)
	end)
	
	-- warn and stop function if something goes wrong
	if not success then
		warn(message)
		return
	end
	
	-- if player own pass (bomb)
	if hasPass then
		givePlayerBomb(player)
	end
	
end
game.Players.PlayerAdded:Connect(newPlayer)

If that doesn’t work, can you add print() statements?

Yes, the bomb is a tool in replicatedstorage

Ok, just start working backwards, start printing on the spot that connects the function, and keep going till you hit exactly where it stops print, and as always, print all the main stuff, like the haspass, or the bomb. Tell us what you find, and we can work from there.

1 Like

So it turns out that i wasn’t getting the bomb because I didn’t own the pass

Okay don’t roast me I used this script in a game published under my profile and I automatically owned the gamepass, but this is a group game so I don’t automatically get it :grimacing:

1 Like