How would I get GetPropertyChangedSignal to work BETTER?

I have a 2x points type script going on, but the issue is, the player can change the value in the shop and I want it to multiply it by two.

local function ownsgamepass(userid,gamepassid)
	local s,res = pcall(MPS.UserOwnsGamePassAsync,MPS,userid,gamepassid)
	if not s then
		res = false
	end
	return res
end

if ownsgamepass(player.UserId, 80845457) then
	script.Parent.Text = "Owned"
	player.OwnGamepasses.Clicks2.Value = true

	game:GetService("StarterGui"):SetCore("SendNotification", {
		Title = "Gamepass Loaded",
		Text = "'2x Clicks' gamepass has been loaded.",
		Duration = 5
	})

local newVal = player.leaderstats.ClickValue.Value * 2
		player.leaderstats.ClickValue.Value = newVal

	player.leaderstats.ClickValue:GetPropertyChangedSignal("Value"):Connect(function()
		local newVal = player.leaderstats.ClickValue.Value * 2
		player.leaderstats.ClickValue.Value = newVal
		print("New val : "..newVal)
	end)
end

I tried looping, that makes it just go up infinite,I tried a debounce, doesnt work.

What I have right now repeats like 6 times???
image

Any solutions??? I thought seeing the GetPropertyChangedSignal would work fine.

It’s because you’re changing the value inside the function which would fire the function again.

how would i avoid this since debounce isnt working

Try this:

local debounce = false

local function ownsgamepass(userid, gamepassid)
	local s, res = pcall(MPS.UserOwnsGamePassAsync, MPS, userid, gamepassid)
	
	if not s then
		res = false
	end
	
	return res
end

if ownsgamepass(player.UserId, 80845457) then
	script.Parent.Text = "Owned"
	player.OwnGamepasses.Clicks2.Value = true

	game:GetService("StarterGui"):SetCore("SendNotification", {
		Title = "Gamepass Loaded",
		Text = "'2x Clicks' gamepass has been loaded.",
		Duration = 5
	})

	local newVal = player.leaderstats.ClickValue.Value * 2
	player.leaderstats.ClickValue.Value = newVal

	player.leaderstats.ClickValue:GetPropertyChangedSignal("Value"):Connect(function()
		if debounce then
			return
		end
		
		debounce = true
		
		player.leaderstats.ClickValue.Value *= 2
		
		task.wait(0.5)
		debounce = false
	end)
end
player.leaderstats.ClickValue.Changed:Connect(function(value)
	if debounce then
		return
	end

	debounce = true

	player.leaderstats.ClickValue.Value = value * 2

	task.wait(0.5)
	debounce = false
end)

This only works for when selected the 1x multiplier and only sometimes the 2x some reason?

Video below.

Copied script exactly as you sent basically so not sure what the issue is.

edit

this is the whole thing incase that makes a difference

local players = game:GetService("Players")
local player = players.LocalPlayer
local MPS = game:GetService("MarketplaceService")
local id = 80845457
local debounce = false

local function ownsgamepass(userid,gamepassid)
	local s,res = pcall(MPS.UserOwnsGamePassAsync,MPS,userid,gamepassid)
	if not s then
		res = false
	end
	return res
end

script.Parent.MouseButton1Click:Connect(function()
	MPS:PromptGamePassPurchase(player, id)
end)

MPS.PromptGamePassPurchaseFinished:Connect(function(player, id, purchaseSuccsess)
	if purchaseSuccsess == true and id == 80845457 then
		game:GetService("StarterGui"):SetCore("SendNotification", {
			Title = "Completed",
			Text = "Your purchase has been completed.",
			Duration = 5
		})
		script.Parent.Text = "Owned"

		player.OwnGamepasses.Clicks2.Value = true
	else
		game:GetService("StarterGui"):SetCore("SendNotification", {
			Title = "Failed",
			Text = "Your purchase was failed.",
			Duration = 5
		})
	end
end)


if ownsgamepass(player.UserId, 80845457) then
	script.Parent.Text = "Owned"
	player.OwnGamepasses.Clicks2.Value = true

	game:GetService("StarterGui"):SetCore("SendNotification", {
		Title = "Gamepass Loaded",
		Text = "'2x Clicks' gamepass has been loaded.",
		Duration = 5
	})

	local newVal = player.leaderstats.ClickValue.Value * 2
	player.leaderstats.ClickValue.Value = newVal

	player.leaderstats.ClickValue.Changed:Connect(function(value)
		if debounce then
			return
		end

		debounce = true

		player.leaderstats.ClickValue.Value = value * 2

		task.wait(0.5)
		debounce = false
	end)
end