What do you want to achieve?
I want the script to check if the player has the game pass when joining the game, then check if the player has the tool & if the player doesn’t have the tool … the tool will then be cloned into their backpack!
What is the issue?
I don’t think my entire script is running since it’s only printing one of the prints.
The script is in ServerScriptService.
Here’s the script:
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local gamePassID = 73240559
local function onPlayerAdded(player)
local hasPass = false
-- Check if the player already owns the game pass
local success, message = pcall(function()
hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)
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
print(player.Name .. " owns the game pass with ID " .. gamePassID)
local Backpack = player:WaitForChild("Backpack")
if player.Backpack:FindFirstChild("Hello Kitty's Wand") then return end--Makes Sure The Player Doesn't Have Tool
print(player.Name .. "player already has Hello Kitty's Wand" .. gamePassID)
-- Assign this player the ability or bonus related to the game pass
local Tool = game.ServerStorage.Shop["Hello Kitty's Wand"]:Clone()
Tool.Parent = player.Backpack
print(player.Name .. "Hello Kitty's Wand given to player" .. gamePassID)
end
end
-- Connect "PlayerAdded" events to the "onPlayerAdded()" function
Players.PlayerAdded:Connect(onPlayerAdded)
Is there something wrong with the script that’s causing it not to work correctly?
Doesn’t seem like theres any problems with the script.
Put a print check in the if statement that checks if the tool is already in the players backpack. Im sure thats why the whole function is not running fully.
if player.Backpack:FindFirstChild("Hello Kitty's Wand") then
print(player.Name .. "player already has Hello Kitty's Wand" .. gamePassID)
return end--Makes Sure The Player Doesn't Have Tool
This is what prints after altering the script; however, I believe that the script is working properly because it isn’t giving me multiples of the same tool … which is what I want to happen.
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local gamePassID = 73240559 -- Change this to your game pass ID
local function onPlayerAdded(player)
local hasPass = false
-- Check if the player already owns the game pass
local success, message = pcall(function()
hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)
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
print(player.Name .. " owns the game pass with ID " .. gamePassID)
local Backpack = player:WaitForChild("Backpack")
if player.Backpack:FindFirstChild("Hello Kitty's Wand") then
print(player.Name .. "already has Hello Kitty's Wand " .. gamePassID)
return end--Makes Sure The Player Doesn't Have Tool
-- Assign this player the ability or bonus related to the game pass
local Tool = game.ServerStorage.Shop["Hello Kitty's Wand"]:Clone()
Tool.Parent = player.Backpack
wait (.1)
print(player.Name .. " has been given Hello Kitty's Wand " .. gamePassID)
end
end
-- Connect "PlayerAdded" events to the "onPlayerAdded()" function
Players.PlayerAdded:Connect(onPlayerAdded)
Thanks for this! Your post will definitely be a useful resource in the future!
I have an Inventory DataStore so I don’t want my tool to be cloned each time the player joins the game since then they’d have like 6 wands when they really only need one. It makes it a bit tricky but I think my script works … I hope!