Purchase System Not Working

Hello, Im making a product purchas system, it works perfectly, other than when the player clicks it, it will prompt the purchase to the last player to click it even though a different player clicked it. My Code:


	local var = game.Players:GetPlayerByUserId(game.Workspace:WaitForChild("Variabled").PlayersUserId.Value)

	local MarketPlace = game:GetService("MarketplaceService")
	local Id = script.Parent.Id.Value
	local Player = game.Players:GetPlayerByUserId(game.Workspace.Variabled.PlayersUserId.Value)
print(Player.Name.."Server Purchas A")
	MarketPlace:PromptPurchase(Player, Id)
	MarketPlace.PromptPurchaseFinished:Connect(function(player, assetId, isPurchased)
		if isPurchased then		
			print(game.Players:GetPlayerByUserId(game.Workspace.Variabled.PlayersUserId.Value).Name.." Tiped Robux")
			local amount = MarketPlace:GetProductInfo(Id).PriceInRobux
			Player.leaderstats.Donated.Value = Player.leaderstats.Donated.Value + amount
			local StandOwner = game.Players:GetPlayerByUserId(script.Parent.Parent.Parent.Parent.Parent.Name)

			StandOwner.leaderstats.Raised.Value = StandOwner.leaderstats.Raised.Value + amount
			script.Parent.Parent.Parent.Parent.Parent.Base.SurfaceGui.Raised.Text = StandOwner.leaderstats.Raised.Value.." Robux Raised"
			script.Parent.Parent.Parent.Parent.Parent.Base.ParticleEmitter.Enabled = true
			local remote = game.ReplicatedStorage:WaitForChild("ServerMessage")
			local rblxAmount = MarketPlace:GetProductInfo(Id).PriceInRobux
			remote:FireAllClients("[System] "..Player.Name.." Donated "..StandOwner.Name.." "..rblxAmount.." Robux!", Color3.fromRGB(255, 170, 0), Enum.Font.SourceSansBold, Enum.FontSize.Size24)
			Player.Coin.Value = Player.Coin.Value+10
			script.Parent.Parent.Parent.Parent.Parent.Base.ParticleEmitter.Enabled = false
			Player = nil
			Player = nil
			print("Item Already Owned!")


Please Help, Mason

Okay there’s missing info here, how is the PlayersUserId value being set? And where?
As well as issues.

  1. Make references instead of doing script.Parent.Parent.stopitalready spaghetti. It’s cleaner and lets you verbosely name the variables to explain what it is instead of following spaghetti noodles to the end of the fork.

  2. Don’t keep assigning a connection to MarketplaceService every time someone clicks it. It’s an event that will go off every single time someone purchases something, and the reason AssetId is provided is so you can tell what they purchased. Only define it once, and outside of the MouseButton1Click Connection.

Anyways, please provide me with more info as to what is setting PlayersUserId.