This script errors with "Unable to cast value to Object" I am not sure why as I'm pretty sure I'm including the player object. Let me know why.
Errors on Lines 51, 55, and 59 depending on which button you click.
local product1 = 616014127 local product2 = 616014380 local product3 = 616014575 --------------------Main stuff----------------------------------------------------------- local datastore = game:GetService("DataStoreService") local market = game:GetService("MarketplaceService") local totalamount = datastore:GetDataStore("RobuxRaised") local datakey = ("aafneueu7378348734bg") local product1price = market:GetProductInfo(product1,Enum.InfoType.Product).PriceInRobux local product2price = market:GetProductInfo(product2,Enum.InfoType.Product).PriceInRobux local product3price = market:GetProductInfo(product3,Enum.InfoType.Product).PriceInRobux local button1 = script.Parent.Donate1.SurfaceGui.TextButton local button2 = script.Parent.Donate2.SurfaceGui.TextButton local button3 = script.Parent.Donate3.SurfaceGui.TextButton local raisedtext = script.Parent.TotalDonated.SurfaceGui.TextLabel --[[ local loadamount = totalamount:GetAsync(datakey) if not loadamount then pcall(function() totalamount:SetAsync(datakey,0) end) else raisedtext.Text = "Total Donated: "..loadamount.."R$" end while true do raisedtext.Text = "Total Donated: "..loadamount.."R$" wait(3) end --]] button1.Text = product1price.." R$" button2.Text = product2price.." R$" button3.Text = product3price.." R$" button1.MouseButton1Down:Connect(function(plr) market:PromptProductPurchase(plr,product1) --These error end) button2.MouseButton1Down:Connect(function(plr) market:PromptProductPurchase(plr,product2) --These error end) button3.MouseButton1Down:Connect(function(plr) market:PromptProductPurchase(plr,product3) --These error end)
You're using the first argument given by MouseButton1Down which is the x screen position for the mouse. See the other parameters here.
Since this is done locally you have access to the LocalPlayer from the Players service.
--Example usage for one product id. local Players = game:GetService("Players") local market = game:GetService("MarketplaceService") local player = Players.LocalPlayer --This is what is needed local button1 = script.Parent.Donate1.SurfaceGui.TextButton local product1 = 616014127 local function PromptPurchaseOnClick() market:PromptPrudctPurchase(player, product1) end --Omitted position parameters here since we don't need them at all button1.MouseButton1Down:Connect(PromptPurchaseOnClick)
I recommend trying to organize your variable names. Here are further articles to help you with Developer products:
I have fixed this buy replacing the text buttons with click detectors. I appreciate you all trying to help.