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:
script.Parent.MouseButton1Click:Connect(function()
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
print(amount)
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.MoneySong:Play()
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
wait(10.71)
script.Parent.Parent.Parent.Parent.Parent.Base.ParticleEmitter.Enabled = false
Player = nil
else
Player = nil
print("Item Already Owned!")
end
end)
end)
Please Help, Mason