Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I get a specific player's PlayerGui through a script?

Asked by 5 years ago

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!

2 answers

Log in to vote
0
Answered by
royaltoe 5144 Moderation Voter Community Moderator
5 years ago

You can use a click detector to get the player who clicked the button in the workspace.

Then you do your MarketplaceService:PromptProductPurchase(plr, productID) line.

local clickDetector = workspace.Part.ClickDetector

function onMouseClick(player)
    print(player.Name .. " clicked me!")
    MarketplaceService:PromptProductPurchase(player, productID)
end

clickDetector.MouseClick:connect(onMouseClick)

0
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. royaltoe 5144 — 5y
0
Thank you so much! EstrangedFisherman 51 — 5y
0
:D royaltoe 5144 — 5y
Ad
Log in to vote
-1
Answered by 5 years ago

You seem to have no idea of the difference between LocalScripts and Scripts and how Roblox handles networking between the client and the server.

I recommend you to look at it. There are lots of articles about it.

And LocalScripts run only in StarterGui (PlayerGui), StarterPlayerScripts and Backpack.

That's a start I guess. It's not much of an answer though.

0
Thanks for the feedback. I already know that Local Scripts don't function in every part of the game, but I definitely could become more knowledgeable about how ROBLOX handles networking between the Client and Server. EstrangedFisherman 51 — 5y
0
You probably won't see this and don't care about this rn but I really really felt the need to say this. I am very extremely sorry for what I said. I don't know what I was thinking, I should've said sorry 6+ months ago (or just never posted this stupid "answer") but I quit SH for a while. Also, I hope you are a better scripter (and will always be) than last time my stupid past self talked to you. GGRBXLuaGG 417 — 4y

Answer this question