I've been trying to figure this issue out for the longest time now, and I'm going to try my best to explain my problem.
--local GetGui = game.StarterGui.MoneyMarket.Buttons.b729977067
--print(GetGui)
local MarketplaceService = game:GetService("MarketplaceService")
local Playerss = game:GetService("Players")
--Playerss:GetPlayerFromCharacter()
local productID = 729977067
print(productID)
local function promptPurchase(plr)
if script.Parent.Owner == nil then
return
else
MarketplaceService:PromptProductPurchase(plr, productID)
end
end
Basically what I'm trying to do is get this script I'm working on [ above ] to add money into the player's tycoon after they make a purchase with ROBUX. The issue is that I can't find a way to get to the player's PlayerGui so the script knows when to run the function above.
The location of the script is in a tycoon kit model, that is also inside the workspace. I'm trying to get to a button Gui in the PlayerGui, so it knows to run this code. So far I've tried doing:
GetGui.MouseButton1DownClick:Connect(promptPurchase)
But that line of code was not working AT ALL so I figured that I HAD to go into the PlayerGui.
I also thought maybe I could use a Local Script so I could use LocalPlayer in order to find that specific player and then go into their PlayerGui, but the tycoon kit that I'm using makes it easiest if I place the script in the kit. And Local Scripts don't work in the workspace. And putting that script outside the tycoon kit and workspace will make it difficult to find the tycoon kit the player is working on since there'll be 10 tycoons kits named "TycoonKit" in the game. I don't know quite exactly how I would find that player's tycoon kit that he took ownership to build his tycoon if I take it out of it.
The last idea that I thought could work was using the character in the workspace to get to the player, but I'm still not sure if that would work. I would still need a way to find the right owner of that tycoon to then get to that character in the workspace. There's a value for the name of the owner of every tycoon, so I was thinking I could use that value, put it in a variable, then try to find the character in the workspace, and then after all that use the:
:GetPlayerFromCharacter()
line to get to the player. But that was all an idea and I really am not sure on the best way to do that.
I'm still very new to Lua and coding and I'm really trying my best, but I'm not sure if there is any way to figure this out with what I've explained, but if there is I'd really appreciate the answer it would help me so much in the future too. Thanks!

3 comments
When you're in the workspace, always access the player through an event that passes in the player like the one above. Things in the workspace that call for a specific character are almost always caused by events. Otherwise, if it's not. then you're better off using a local script.
Thank you so much!
:D