What do you want to achieve?
Here is the step by step process I’m trying to achieve:
- I want the ClickPart to check if the player has the gamepass.
- Check if the player already has the item in their inventory, if so the ‘Repeat’ ScreenGUI will appear on their screen.
- If the player owns the gamepass but doesn’t have the item in their inventory, the item will be cloned into their backpack & the ‘Success’ ScreenGUI will appear. (If they try to purchase the item again, they won’t be able to since it’s already in their backpack).
- If the player doesn’t own the gamepass then the ‘Failed’ ScreenGUI will appear & the item won’t be put into their backpack.
What is the issue?
The ‘Repeat’ ScreenGUI appears but the ‘Failed’ & ‘Success’ ScreenGUIs do not.
- What solutions have you tried so far?
I’ve tried re-writing my code many times & it still won’t work the way I want it to. Is there something wrong with my code? I’m not getting any output errors but it’s not working the way I want it to.
Here’s the code:
--local RequiredGold = script.Parent.Parent.Parent.Price.Value
local player = game.Players.LocalPlayer
local tool = game.ServerStorage.Shop["Hello Kitty's Wand"]
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local gamePassID = 73240559 -- Change this to your game pass ID
local hasPass = false
local debounce = false
script.Parent.MouseClick:Connect(function(player)
-- 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")
-- return end--Makes Sure The Player Doesn't Have Tool
if player.Backpack:FindFirstChild("Hello Kitty's Wand") then
print(player.Name .. "already has Hello Kitty's Wand " .. gamePassID)
player.PlayerGui:FindFirstChild("Repeat")
local Repeat = script.Repeat:clone()
Repeat.Parent = player.PlayerGui
wait(2)
Repeat:Destroy()
debounce = false
else
if not debounce then -- Here is the debounce!
debounce = true
if hasPass == true then
print(player.Name .. " has been given Hello Kitty's Wand " .. gamePassID)
player.PlayerGui:FindFirstChild("Success")
local Success = script.Success:clone()
Success.Parent = player.PlayerGui
wait(2)
tool:Clone().Parent = player.Backpack
player.Character.Humanoid:UnequipTools()
Success:Destroy()
else
if hasPass == false then
player.PlayerGui:FindFirstChild("Failed")
local Failed = script.Failed:clone()
Failed.Parent = player.PlayerGui
wait(2)
Failed:Destroy()
end
debounce = false -- place is outside of the other function so it can restart the process.
end
end
end
end
end)