I have a script that when it detects you have a certain gamepass takes the item from server storage and places it in your backpack. The script works in other games but not this one and I am really confused. Any help appreciated.
Script:
local MarketPlaceService = game:GetService(āMarketplaceServiceā)
local GamepassId = 15090522
local Tool = game.ServerStorage[āGoldenBoomBoxā]
game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
if MarketPlaceService:UserOwnsGamePassAsync(Player.UserId, GamepassId) then
local ToolClone = Tool:Clone()
ToolClone.Parent = Player.Backpack
end
end)
end)
1 Like
I feel like you may need to turn this on if possible, also check if the Tool is equal to where it actually is
Are you using an alt account? Cause thereās someone else who asked for the exact same thing.
No iām not, idk what is going on
try replacing
local Tool = game.ServerStorage["GoldenBoomBox"]
with
local Tool = game.ServerStorage:WaitForChild("GoldenBoomBox")
Still no luck, thereās no output either
Hello!
I added pcall for security reasons, otherwise, this code definitely works. Try printing out hasGamePass value. Are you sure you own a gamepass? Is the gamepass ID correct? Make sure that the script (server script) is located in ServerScriptService (I accidentally put it inside ServerStorage at first ). Third party sales can be disabled and character is also already loaded by the time tool is copied.
local MarketPlaceService = game:GetService("MarketplaceService")
local GAMEPASS_ID = 15090522
-- correct path required
local tool = game:GetService("ServerStorage")["Golden Boom Box"]
game:GetService("Players").PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local hasGamePass; local success, err = pcall(function()
hasGamePass = MarketPlaceService:UserOwnsGamePassAsync(player.UserId, GAMEPASS_ID)
end)
if (not success) then
warn("Something went wrong while trying to access user's gamepass data.")
end
if (hasGamePass) then tool:Clone().Parent = player.Backpack end
end)
end)
1 Like