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

FInding the player for MouseButton1Click?

Asked by 9 years ago

Hey, guys. I'm trying to make a gui appear on the screen when you click on a part. I've already achieved doing this using a Click Detector inside the part, but I was wondering how you would accomplish this using Suface Gui. This is what I tried doing so far:

script.Parent.MouseButton1Click:connect(function(Player)
    local part = script.Parent.Parent.Parent
    local gui = part:FindFirstChild("ScreenGui")
    part.BrickColor = BrickColor.new("Really red")
    if gui then
        local newgui = gui:Clone()
        newgui.Parent = Player.PlayerGui
    end
    wait(1)
    part.BrickColor = BrickColor.new("Dark stone grey")
end)

As you can see, the color of the brick changes red as expected (line 4), but the gui doesn't clone (line 7). I'm having trouble figuring out how I would locate the player that clicked the part, and I would gladly appreciate anyone how could help me solve this problem.

0
MouseButton1Click does not return player. Ryzox 220 — 9y

1 answer

Log in to vote
0
Answered by
Ryzox 220 Moderation Voter
9 years ago

MouseButton1Clickdoes not return "Player". The best way to do this is to make this into a LocalScriptdefining player as LocalPlayer, you will then have to set the Adorneeof the SurfaceGuito the part in workspaceyou would like it to appear on.

Ad

Answer this question