Making a flashlight gamepass and whenever a player joins it checks if he owns the pass and if he does it will give him the flashlight and print player owns the pass otherwise it won’t give him anything and it will print player does own the pass, So I bought the pass in game and rejoined and it prints player owns pass but it doesn’t give me the flashlight but when I tested it in studio it prints player owns it as well but it gives me the flashlight. So I am unsure why it doesn’t in game, Any idea? Script:
local MPS = game:GetService("MarketplaceService")
local MPSID = 64276836
local Flashlight = game:GetService("ReplicatedStorage").Flashlight
game.Players.PlayerAdded:Connect(function(player)
if MPS:UserOwnsGamePassAsync(player.UserId, MPSID) then
Flashlight:Clone().Parent = player.Backpack
print("Players that joined owns flashlight")
else
print("Player that joined does not own flashlight")
end
end)
The problem is that it takes time to get the services, so the player already joined before the playeradded event is set. You have to loop through all players before the player added event and do the same thing. This is what i had to do in my game. Make the playeradded function seperate, so it can be called again in the loop.
He said it prints meaning the PlayerAdded fired, the issue you described happens when the event is connected too late aka below other yielding code so this isn’t the case.
Hello friends, this is because you will be adding the flashlight tool directly into the players backpack most likely before they even spawned in. This will also cause them to loose the flashlight once they respawn anyway.
Instead you should simply be:
Wait for player added
Do they own the gamepass?
If yes, add the gamepass to their startergear
Are they already spawned in?
If yes, also clone it to their backpack directly.
local MPS = game:GetService("MarketplaceService")
local Flashlight = game:GetService("ReplicatedStorage").Flashlight
local PassID = 64276836
game.Players.PlayerAdded:Connect(function(Player)
if MPS:UserOwnsGamePassAsync(Player.UserId, PassID) then
Flashlight:Clone().Parent = Player.StarterGear
if Player.Character then
Flashlight:Clone().Parent = Player.Backpack
end
end
end)