Help with gamepass script

I am trying to make an Intvalue change to a gamepass ID

When I press the button, the value stays at 0
I have tried putting the number in parenthesis, but it did not work
Here is the script:

local button = script.Parent
local imgid = "13032830495"
local passid = 159094616
purchasemenu = game.Players.LocalPlayer.PlayerGui.ScreenGui.Menus.Shop.PurchaseMenu

button.MouseButton1Click:Connect(function()
	purchasemenu.Gpassicon.Image="rbxassetid://"..imgid
	purchasemenu.purchase.passid.Value=passid 
end)

You didn’t concatenate this line properly, here is how you do it:

purchasemenu.Gpassicon.Image = ("rbxassetid://" .. imgid)

Could it be that you are changing the IntValue in a local script and trying to read it in a server script? or vice-versa? Could you explain more of the project structure and what is reading from purchasemenu.purchase.passid

1 Like

The image loads without that, and adding that did not solve the issue

This does nothing different.

This code should work if you set up everything properly. Could you show me your explorer?

You shouldn’t use unnecessary references to objects when you can just use script.Parent, because it could confuse you into referencing the wrong object.

Fixed code:

--//Variables
local Button = script.Parent

--//Controls
local passId = 159094616

--//Functions
Button.MouseButton1Down:Connect(function()
	Button.Parent.Gpassicon.Image = "rbxassetid://13032830495"
	Button.passid.Value = passId
	print(Button.passid.Value) --//Should print 159094616
end)

Also, if this doesn’t work, please tell me what it printed and the errors if there are any.

I shouldve mentioned, the value is supposed to change when you click the “Speed” button, not the purchase button, the purchase button just grabs the Intvalue and prompts a gamepass purchase with the value it has, but when I click the speed button, the intvalue is supposed to change to the gamepass ID but it stays at 0

Show me your explorer for the speed button then.

Change your code to this:

--//Variables
local Button = script.Parent
local PurchaseMenu = Button.Parent.PurchaseMenu

--//Controls
local passId = 159094616

--//Functions
Button.MouseButton1Down:Connect(function()
	PurchaseMenu.Gpassicon.Image = "rbxassetid://13032830495"
	PurchaseMenu.purchase.passid.Value = passId
	print(Button.passid.Value) --//Should print 159094616
end)

Didnt print anything and the value stayed at 0

Okay, that’s weird. I have a feeling your script isn’t even running for some reason because I tried replicating your situation and it worked for me, could you send a placefile?

Baseplate.rbxl (64.5 KB)

this is all of the GUI.

You should’ve told me way earlier that there was an error.

Fixed place:
Baseplate (1).rbxl (64.4 KB)

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.