I was recently creating a gamepass for the player to play their own music in my game, and the gamepass was inserted fine. The only problem is that the gamepass wouldn’t actually work.
The tool itself is fine. It works when I place it in my player’s StarterPack, but it doesn’t work when I place it in ReplicatedStorage to be cloned as a gamepass item.
The gamepass item is a boombox. The gear is inserted into the player’s inventory, and they can hold it out. But when you click, the Music ID input wouldn’t appear (Where it asks for an audio ID, and has a play button beneath it)
Example photo:
I didn’t use a model from the Toolbox, I inserted the gear ID into the EasyInsert plugin (EasyInsert is a plugin that allows you to insert items through its ID. This makes it helpful to insert player models, assets, and functioning gears)
This script is currently placed in StarterGUI as a local script. The boombox tool is placed in ReplicatedStorage.
TL:DR: Boombox item is inserted to backpack when the user owns the gamepass, but the boombox doesn’t work in-game.
Solution:
local players = game:GetService("Players") -- the players service
local market = game:GetService("MarketplaceService") -- marketplace service
local function playerOwnsGamepass(player, id)
-- function used to check if the player owns a game pass
return market:UserOwnsGamePassAsync(player.UserId, id)
-- return either true/false
-- if roblox's servers are down, this can error. To combat that, you'd have to wrap this in a pcall
end
local function onPlayerAdded(player)
if playerOwnsGamepass(player, 17831009) then
-- since the function returns a boolean (true/false) you can structure it like this since it's only used once
-- copies the boombox into the player's inventory
game:GetService("ReplicatedStorage"):WaitForChild("SuperFlyGoldBoombox"):Clone().Parent = player.Backpack
end
end
players.PlayerAdded:Connect(onPlayerAdded)
-- function/event to detect when a player joins and calls the "onPlayerAdded" function
for _, plr in ipairs(players:GetPlayers()) do
-- loops through possible players who're in the game/connected before this script loaded
coroutine.wrap(onPlayerAdded)(plr) -- wrapped in a coroutine so that the loop can progress without waiting
end
This is unrelated to your problem but if you’re doing this on the client then exploiters can easily bypass this and give themselves the item.
Also, your issue may have to do with the fact that you’re cloning it from the client. The boombox has a server script, meaning, when the local script clones it, the server script won’t run because on the server, the server script is still in replicated storage.
HugeCoolboy is right. I cloned the boombox from the server and it worked perfectly.
Then I tried cloning it from the local script and the gui didn’t show up.
In-case you don’t know how to structure your server script code, it should be like this:
local players = game:GetService("Players") -- the players service
local market = game:GetService("MarketplaceService") -- marketplace service
local function playerOwnsGamepass(player, id)
-- function used to check if the player owns a game pass
return market:UserOwnsGamePassAsync(player.UserId, id)
-- return either true/false
-- if roblox's servers are down, this can error. To combat that, you'd have to wrap this in a pcall
end
local function onPlayerAdded(player)
if playerOwnsGamepass(player, 17831009) then
-- since the function returns a boolean (true/false) you can structure it like this since it's only used once
-- copies the boombox into the player's inventory
game:GetService("ReplicatedStorage"):WaitForChild("SuperFlyGoldBoombox"):Clone().Parent = player.Backpack
end
end
players.PlayerAdded:Connect(onPlayerAdded)
-- function/event to detect when a player joins and calls the "onPlayerAdded" function
for _, plr in ipairs(players:GetPlayers()) do
-- loops through possible players who're in the game/connected before this script loaded
coroutine.wrap(onPlayerAdded)(plr) -- wrapped in a coroutine so that the loop can progress without waiting
end
After testing the code, it seems that the boombox wouldn’t appear in the player’s inventory. I don’t know if its on my part, but I did follow what you instructed on the code.
The server script was placed into ServerScriptService
The tool is still in ReplicatedStorage
But there is no boombox clone.
The only change I made was deleting the LocalScript originally.
Are there any changes I need to make on the provided script?
I might’ve made a slight typo somewhere (I was in a slight rush). You can try to see if the output has any errors. If it doesn’t, you can create print calls for debugging and to see what the script is doing.
example
local function onPlayerAdded(player)
if playerOwnsGamepass(player, 17831009) then
print(player.Name, "owns the gamepass")
game:GetService("ReplicatedStorage"):WaitForChild("SuperFlyGoldBoombox"):Clone().Parent = player.Backpack
else
print(player.Name, "does not own the gamepass")
end
end
The output log should print one of these and that could help you a bit.