If Player has game Pass, When Joins Server To Have A Specific Tool, I Tried but it doesn't work!
local MarketplaceService = game:GetService("MarketplaceService") local Players = game:GetService("Players") local gamePassID = 440994981 -- Change this to your game pass ID function onPlayerSpawned(player) local hasPass = false -- Check if the player already owns the game pass local success, message = pcall(function() hasPass = MarketplaceService:UserOwnsGamePassAsync(player.userId, gamePassID) print("Has Game Pass for Gun") end) -- If there's an error, issue a warning and exit the function if not success then warn("Error while checking if player has pass: " .. tostring(message)) return end if hasPass == true then game.ServerStorage.GravityCoil:clone().Parent = player.Backpack end end game.Players.PlayerAdded:connect(function(player) player.CharacterAdded:connect(function() onPlayerSpawned(player) end) end) -- Connect 'PlayerAdded' events to the 'onPlayerAdded()' function Players.PlayerSpawned:Connect(onPlayerSpawned)
Try this..
Be sure to capitalize Connect and Clone, and we also changed PlayerSpawned to PlayerAdded, because PlayerSpawned does not work.
local MarketplaceService = game:GetService("MarketplaceService") local Players = game:GetService("Players") local gamePassID = 440994981 -- Change this to your game pass ID function onPlayerSpawned(player) local hasPass = false -- Check if the player already owns the game pass local success, message = pcall(function() hasPass = MarketplaceService:UserOwnsGamePassAsync(player.userId, gamePassID) print("Has Game Pass for Gun") end) -- If there's an error, issue a warning and exit the function if not success then warn("Error while checking if player has pass: " .. tostring(message)) return end if hasPass == true then game.ServerStorage.GravityCoil:Clone().Parent = player.StarterGear end end -- Connect 'PlayerAdded' events to the 'onPlayerAdded()' function Players.PlayerAdded:Connect(onPlayerSpawned)
I see your problem, you never made it clear that the players hasPass is true or not. Use this script instead:
local MarketplaceService = game:GetService("MarketplaceService") local Players = game:GetService("Players") local gamePassID = 440994981 -- Change this to your game pass ID function onPlayerSpawned(player) local hasPass = false -- Check if the player already owns the game pass local success, message = pcall(function() hasPass = MarketplaceService:UserOwnsGamePassAsync(player.userId, gamePassID) hasPass = true end) -- If there's an error, issue a warning and exit the function if not success then warn("Error while checking if player has pass: " .. tostring(message)) return end if hasPass == true then game.ServerStorage.GravityCoil:clone().Parent = player.Backpack end end game.Players.PlayerAdded:connect(function(player) player.CharacterAdded:connect(function() onPlayerSpawned(player) end) end)
I see your problem, you never made it clear that the players hasPass is true or not. Use this script instead:
local MarketplaceService = game:GetService("MarketplaceService") local Players = game:GetService("Players") local gamePassID = 440994981 -- Change this to your game pass ID function onPlayerSpawned(player) local hasPass = false -- Check if the player already owns the game pass local success, message = pcall(function() hasPass = MarketplaceService:UserOwnsGamePassAsync(player.userId, gamePassID) hasPass = true end) -- If there's an error, issue a warning and exit the function if not success then warn("Error while checking if player has pass: " .. tostring(message)) return end if hasPass == true then game.ServerStorage.GravityCoil:clone().Parent = player.Backpack end end game.Players.PlayerAdded:connect(function(player) player.CharacterAdded:connect(function() onPlayerSpawned(player) end) end)