Hey, so I am currently developing a vibe game and I made a script that’s meant to give you a glowstick if you own the gamepass, it works in studio but in an actual roblox server it gives random items, could someone help?
Script:
local MarketplaceService = game:GetService(“MarketplaceService”)
local Players = game:GetService(“Players”)
local gamePassID = 17721832
function Spawned(player)
local HasGamepass = false
local success, message = pcall(function()
HasGamepass = MarketplaceService:UserOwnsGamePassAsync(player.userId, gamePassID)
end)
if not success then
warn("Checking In Player Has Gamepass" .. tostring(message))
return
end
if HasGamepass == true then -- If they own the gamepass
game.ServerStorage.GlowStick:Clone().Parent = player.Backpack
end
end
game.Players.PlayerAdded:Connect(function(player) -- Player added to game
player.CharacterAdded:Connect(function()
Spawned(player)
end)
local MPS = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local GamepassID = 17721832
local function Spawned(Player)
local HasGamepass = false
Player.CharacterAdded:Connect(function(Character)
local success, message = pcall(function()
HasGamepass = MPS:UserOwnsGamePassAsync(Player.UserId, GamepassID)
end)
if not success then
warn("Checking in Player has gamepass: ", message) --No need to return, there's nothing else in the script that you need to return back early
end
if HasGamepass == true then --If they own the gamepass
game.ServerStorage.GlowStick:Clone().Parent = Player.Backpack
end
end)
end
Players.PlayerAdded:Connect(Spawned)
checked every single one and couldnt find any spawn scripts inside anything i just disabled the backpack i dont wanna mess around with it anymore but thanks for trying to help
Does the item you are trying to spawn have a script inside it that rotates through various random items ? Or does one of the other items in your game have a script that is causing this to happen ?
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local gamePassID = 17721832
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function()
local success, message = pcall(function()
hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)
end)
if hasPass then
print("player has the gamepass")
local GlowStick = game.ReplicatedStorage.GlowStick:Clone()
GlowStick.Parent = player.Backpack
end
end)
end)
local function onPromptGamePassPurchaseFinished(player, purchasedPassID, purchaseSuccess)
if purchaseSuccess == true and purchasedPassID == gamePassID then
print(player.Name.."purchased the game pass!")
local GlowStick = game.ReplicatedStorage.GlowStick:Clone()
GlowStick.Parent = player.Backpack
end
end
MarketplaceService.PromptGamePassPurchaseFinished:Connect(onPromptGamePassPurchaseFinished)
Also make sure that script is in Server Script Service and the item that you want the gamepass to give is in Replicated Storage. Be sure your item name is spelled correctly and matches in the script. You should not have more than one item with the same name.
local mps = game:GetService("MarketplaceService")
local function checkplrgamepass(plr)
if mps:UserOwnsGamePassAsync(plr.UserId, gamepassId) then
game.ReplicatedStorage:WaitForChild("GlowStick"):Clone().Parent = player.Backpack -- Placing the tool in replicated storage would be better
print("Player has recieved the gamepass tool")
else
print("Player don't have gamepass for tool") -- tells player don't have gamepass
end
end)
game.Players.PlayerAdded:Connect(function(player)
wait(5) -- cooldown for loading if anything to load in the server
checkplrgamepass(player)
end)
Basically, when the first player joins the server might not loading fully so it can say “tool not found”, so this script might help it work.
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local gamePassID = 17721832
function Spawned(player)
local HasGamepass = false
local success, message = pcall(function()
HasGamepass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)
end)
if not success then
return warn("Checking In Player Has Gamepass" .. tostring(message))
end
if not HasGamepass then
return warn('Player does not own Gamepass.')
end
player.CharacterAdded:Connect(function()
game.ServerStorage.GlowStick:Clone().Parent = player.Backpack
end)
end
game.Players.PlayerAdded:Connect(Spawned)