I only get the gamepass tool in studio, but not in game.
Studio:
Roblox:
Script:
local Players = game:GetService("Players")
local MarketPlaceService = game:GetService("MarketplaceService")
local ServerStorage = game:GetService("ServerStorage")
local Tools = ServerStorage.Tools
Players.PlayerAdded:Connect(function(Player)
print(Player.Name)
if MarketPlaceService:UserOwnsGamePassAsync(Player.UserId, 54156299) then
Tools.HealingPotion:Clone().Parent = Player.Backpack
end
if MarketPlaceService:UserOwnsGamePassAsync(Player.UserId, 54155868) then
Tools.SpeedCoil:Clone().Parent = Player.Backpack
end
if MarketPlaceService:UserOwnsGamePassAsync(Player.UserId, 54155692) then
Tools.Flashlight:Clone().Parent = Player.Backpack
end
print(MarketPlaceService:UserOwnsGamePassAsync(Player.UserId, 54156299))
end)
Then there’s nothing we can do. The script should work perfectly fine. Therefore, the best conclusion I can tell you is that the problem is a bug like @CremaCoffeeOverseer said.
Now I’m just having random guesses, but usually you put player instead of Player inside the function. For example, Hit and hit are very different. Try using the lower-case letter “player.”
I see. Maybe add a task.wait() in the PlayerAdded event before running the rest of the code in the block. Maybe even add a WaitForChild when parenting the tools to the backpack.
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local GamepassId = 22429147
function PlayerSpawn(Plr)
local PlrHasGamepass = false
local Sucess, FailedTry = pcall(function()
PlrHasGamepass = MarketplaceService:UserOwnsGamePassAsync(Plr.userId, GamepassId)
end)
if not Sucess then
warn("Error while checking if player has gamepass: " .. tostring(FailedTry))
return
end
if PlrHasGamepass == true then
script.Flashlight:Clone().Parent = Plr.Backpack
script.HealingPotion:Clone().Parent = Plr.Backpack
script.SpeedCoil:Clone().Parent = Plr.Backpack
end
end
game.Players.PlayerAdded:connect(function(Player)
Player.CharacterAdded:connect(function()
PlayerSpawn(Player)
end)
end)
Players.PlayerSpawned:Connect(PlayerSpawn)