The title sounds complicated and probably doesn’t make a lot of sense, but it should be a simple fix.
I made a gamepass script where if you own a certain gamepass, it gives you a tool from repstore. the script is in SSS.
However, when you spawn in the first time, you have the tool, but once you reset, the tool dissappears. Here’s a video.
And here’s the script
local MarketplaceService = game:GetService(“MarketplaceService”)
local Players = game:GetService(“Players”)
local repstore = game:GetService(“ReplicatedStorage”)
local gamePassID = 11435761
local function onPlayerAdded(player)
local hasPass = false
local success, message = pcall(function()
hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)
end)
if not success then
warn("Error while checking if player has pass: " … tostring(message))
return
end
if hasPass == true then
print(player.Name … " owns the game pass with ID " … gamePassID)
local backpack = player:FindFirstChildOfClass(“Backpack”)
if backpack then
repstore[“Huge donator sign.”].Parent = backpack
end
local MarketplaceService = game:GetService(“MarketplaceService”)
local Players = game:GetService(“Players”)
local repstore = game:GetService(“ReplicatedStorage”)
local gamePassID = 11435761
local function onPlayerAdded(player)
local hasPass = false
local success, message = pcall(function()
hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)
end)
if not success then
warn("Error while checking if player has pass: " … tostring(message))
return
end
if hasPass == true then
print(player.Name … " owns the game pass with ID " … gamePassID)
local backpack = player:FindFirstChildOfClass(“Backpack”)
if backpack then
repstore[“Huge donator sign.”].Parent = backpack
end
end
player.CharacterAdded:Connect(function()
if hasPass == true then
print(player.Name … " owns the game pass with ID " … gamePassID)
local backpack = player:FindFirstChildOfClass(“Backpack”)
if backpack then
repstore[“Huge donator sign.”].Parent = backpack
end
end
end)
end
Players.PlayerAdded:Connect(onPlayerAdded)
> local MarketplaceService = game:GetService(“MarketplaceService”)
> local Players = game:GetService(“Players”)
> local repstore = game:GetService(“ReplicatedStorage”)
>
> local gamePassID = 11435761
>
> local function onPlayerAdded(player)
>
> local hasPass = false
>
> local success, message = pcall(function()
> hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)
> end)
>
> if not success then
> warn("Error while checking if player has pass: " … tostring(message))
> return
> end
>
> if hasPass == true then
> print(player.Name … " owns the game pass with ID " … gamePassID)
> local backpack = player:FindFirstChildOfClass(“Backpack”)
> if backpack then
> repstore[“Huge donator sign.”].Parent = backpack
> end
> end
>
> player.CharacterAdded:Connect(function()
> if hasPass == true then
> print(player.Name … " owns the game pass with ID " … gamePassID)
> local backpack = player:FindFirstChildOfClass(“Backpack”)
> if backpack then
> repstore[“Huge donator sign.”].Parent = backpack
> end
> end
> end)
> end
>
> Players.PlayerAdded:Connect(onPlayerAdded)
> ```
> [/quote]
>
> still doesnt work...
>
> local MarketplaceService = game:GetService("MarketplaceService")
> local Players = game:GetService("Players")
> local repstore = game:GetService("ReplicatedStorage")
>
> local gamePassID = 11435761
>
> local function onPlayerAdded(player)
>
> local hasPass = false
>
> local success, message = pcall(function()
> hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)
> end)
>
> if not success then
>
> return
> end
>
> if hasPass == true then
> print(player.Name.. " owns the game pass with ID " ..gamePassID)
> local backpack = player:FindFirstChildOfClass("Backpack")
> if backpack then
> repstore["Huge donator sign."].Parent = backpack
> end
> end
>
> player.CharacterAdded:Connect(function()
> if hasPass == true then
> print(player.Name.. " owns the game pass with ID " ..gamePassID)
> local backpack = player:FindFirstChildOfClass("Backpack")
> if backpack then
> repstore["Huge donator sign."].Parent = backpack
> end
> end
> end)
> end
>
> Players.PlayerAdded:Connect(onPlayerAdded)
still doesnt work
Oh, sorry, I have overlooked some small problems. By the way, whenever giving a player something that you will need to give multiple times, you should :Clone() it first.
Here’s code that should hopefully work:
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local repstore = game:GetService("ReplicatedStorage")
local gamePassID = 11435761
local function onPlayerAdded(player)
local hasPass = false
local success, message = pcall(function()
hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)
end)
if not success then
warn("Error while checking if player has pass: "..tostring(message))
return
end
player.CharacterAdded:Connect(function()
if hasPass == true then
print(player.Name .." owns the game pass with ID ".. gamePassID)
local backpack = player:FindFirstChildOfClass("Backpack")
if backpack then
repstore["Huge donator sign."]:Clone().Parent = backpack
end
end
end)
end
Players.PlayerAdded:Connect(onPlayerAdded)
Also, you should check the output in Studio whenever something doesn’t work.
local MarketplaceService = game:GetService(“MarketplaceService”)
local Players = game:GetService(“Players”)
local repstore = game:GetService(“ReplicatedStorage”)
local gamePassID = 11435761
local function onPlayerAdded(player)
local hasPass = false
local success, message = pcall(function()
hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)
end)
if not success then
warn("Error while checking if player has pass: "…tostring(message))
return
end
player.CharacterAdded:Connect(function()
if hasPass == true then
print(player.Name …" owns the game pass with ID "… gamePassID)
local backpack = player:FindFirstChildOfClass(“Backpack”)
local startergear = player:FindFirstChildOfClass(“StarterGear”)
if backpack then
local clonedtool = repstore.Donator:Clone()
clonedtool.Parent = backpack
clonedtool.Parent = startergear
end
end
end)
end
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local repstore = game:GetService("ReplicatedStorage")
local gamePassID = 11435761
local function onPlayerAdded(player)
local hasPass = false
local success, message = pcall(function()
hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)
end)
if not success then
warn("Error while checking if player has pass: " .. tostring(message))
return
end
if hasPass == true then
print(player.Name .. " owns the game pass with ID " .. gamePassID)
local backpack = player:FindFirstChildOfClass("Backpack")
local startergear = player:FindFirstChildOfClass("StarterGear")
if backpack then
repstore["Huge donator sign."]:Clone().Parent = backpack--one to backpack
repstore["Huge donator sign."]:Clone().Parent = startergear--one to startergear
end
end
end
Players.PlayerAdded:Connect(onPlayerAdded)