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

Why is this Clickdetector ScreenGui script not working?

Asked by
huskees -14
5 years ago
script.Parent.MouseClick:connect(function(Clicked)
    game.Players:GetPlayerFromCharacter(Clicked).PlayerGui.ScreenGui.Frame.Visible = true
end)

I'm very new to scripting, so sorry if this is a simple error or wrong all together. I'm trying to be able to click a brick and have a Gui pop up, but whatever I do, it will not work. I'm not getting any errors in the output box, and my Gui works because if I make it visible in StarterGui and test it, I see it. The enter and close buttons work, too, but whatever script I put in the part that is clicked seems to not work. Please help! Thank you. PS - I have a clickdetector, script, and Music in the part.

0
`MouseClick` already returns the player who clicked, so that first bit's redundant. TheeDeathCaster 2368 — 5y
0
script.Parent.MouseButton1Click:Connect(function() ReallyUnikatni 68 — 5y
0
^^ Synth_o 136 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

This is because of two reasons, 1: you cannot get the playergui from the server and 2: the clicked argument is the player that clicked, so you really don't need the GetPlayerFromCharacter function.

workspace.Part.ClickDetector.MouseClick:Connect(function(plrwhoclicked)
    print(plrwhoclicked:GetFullName())
end)

So what you are trying to do here can be accomplished inside a local script as the MouseClick event of the click detector can be used from the client. And on the client, we can modify the playergui as we please. You really only need to check if the plr who clicked is the local player

--local script
local plr = game.Players.LocalPlayer
workspace.Part.ClickDetector.MouseClick:connect(function(player)
    if plr == player then
        plr.PlayerGui.ScreenGui.Frame.Visible = true
    end
end)
Ad

Answer this question