Gamepass GUI: Problem with receiving tools

Hello there,

I am currently having trouble with my gamepass UI I made. Basically the gamepass UI has a buy section and a receive section. So you can buy the pass in game or if you already bought it you can receive it manually.

This is what it looks like

.

What my problem is, is that it lets anyone receive a gamepass tool, whether or not you bought the gamepass. Basically my goal is for my UI to replace the automatic gamepass giver script to prevent the backpack from having too many tools at one time. But I can’t exactly use it if it’s letting people receive it for free. Any help?

Code in my Script
local id = 2929299
 
game.Players.PlayerAdded:connect(function(player)
    if game:GetService("GamePassService"):PlayerHasPass(player, id) then 
        print(player.Name .. " has the game pass!")
    else
        print(player.Name .. " doesn't have the game pass...")
    end
end)
local gamePassValidator = game.ReplicatedStorage:WaitForChild("GamePassValidator")



you=script.Parent.Parent.Parent.Parent.Parent.Parent
script.Parent.MouseButton1Click:connect(function()
if script.Parent.Selected==false then
if game.Lighting:findFirstChild("WarAxe") then
Tool=game.Lighting.WarAxe:clone()
Tool.Parent=you.Backpack
script.Parent.Selected=true
wait(500)
script.Parent.Selected=false
end
end
end)
You can test it here

S&S Testing - Roblox

you=script.Parent.Parent.Parent.Parent.Parent.Parent
script.Parent.MouseButton1Click:connect(function()
if script.Parent.Selected==false then
if game.Lighting:findFirstChild("WarAxe") then
Tool=game.Lighting.WarAxe:clone()
Tool.Parent=you.Backpack
script.Parent.Selected=true
wait(500)
script.Parent.Selected=false
end
end
end)

That’s where it’s giving you the tool, correct?
That doesn’t check if you have the item or not, it just gives you the item regardless.

You would need this check: if game:GetService("GamePassService"):PlayerHasPass(player, id) then
Inside that function and i believe it should then work.
Let me know what happens.

1 Like

I do its just at the top of the script (Same script)

I have this at the top V Then the part you pasted is on the bottom

local id = 2929299
 
game.Players.PlayerAdded:connect(function(player)
    if game:GetService("GamePassService"):PlayerHasPass(player, id) then 
        print(player.Name .. " has the game pass!")
    else
        print(player.Name .. " doesn't have the game pass...")
    end
end)
local gamePassValidator = game.ReplicatedStorage:WaitForChild("GamePassValidator")

Yes, you have it check, but you have it check at the wrong time.

You should have it check when the player clicks it, because the way you have it check serves 0 purpose.
It doesn’t relay that information to the other function.

Try this and tell me what it breaks. :wink:

local id = 2929299
local you = script.Parent.Parent.Parent.Parent.Parent.Parent

script.Parent.MouseButton1Click:connect(function(player)
    if game:GetService("GamePassService"):PlayerHasPass(player, id) then
        print(player.Name .. " has the game pass!")
        if script.Parent.Selected == false then
            if game.Lighting:findFirstChild("WarAxe") then
                Tool = game.Lighting.WarAxe:clone()
                Tool.Parent = you.Backpack
                script.Parent.Selected = true
                wait(500)
                script.Parent.Selected = false
            end
        end
    else
        print(player.Name .. " doesn't have the game pass...")
    end
end)

Also what does this do: local gamePassValidator = game.ReplicatedStorage:WaitForChild("GamePassValidator")

3 Likes

Awesome, I am going to test this out. I’ll let you know if I have any complications.

Alright, so after messing around with it a bit, I came up with this:

Fixed Code
local id = 3008411 --Set to your GamePass ID
local ToolName = "WarAxe" -- Set to whatever tool it clones
local Player = game.Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")

script.Parent.MouseButton1Click:connect(function()
    if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(Player.UserId, id) then
        print(Player.Name .. " has the game pass!")
            if ReplicatedStorage:FindFirstChild(ToolName) then
	            if not Player.Backpack:FindFirstChild(ToolName) then
                    local Tool = ReplicatedStorage:WaitForChild(ToolName):Clone()
                    Tool.Parent = Player.Backpack
	            else
		            print(Player.Name .. " already has " .. ToolName)
		            return
		        end
            end
    else
        print(Player.Name .. " doesn't have the game pass...")
    end
end)

An issue that I had with my previous script I sent was that game:GetService("GamePassService"):PlayerHasPass(player, id)
needed to be game:GetService("MarketplaceService"):UserOwnsGamePassAsync(Player.UserId, id
Due to the update to gamepasses.

Also to make it be more FE friendly I switched your tool to clone out of ReplicatedStorage vs Lighting, and added a variable so that when you want to change your tool name, you only have to change it once at the very top of the script.
Also instead of your 500 second wait acting as a debounce, I replaced that with a check to ensure x Player doesn’t have the item in their backpack, and if they do then it just bypasses the function.


Hope this helps and if you have anymore questions, don’t hesitate to ask! :slight_smile:

1 Like

Awesome, I really appreciate the help. I got an error in the script on Line 19.
image

Do you know how that can be fixed?

Oh yeah, sure thing.

Remove end on Line 18.

1 Like

That fixed the problem, thanks you so much!

1 Like

You’re welcome! Happy to help!

1 Like