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

Open GUI on click not working?

Asked by
oliras3 15
9 years ago

so i got a part that i want to open a gui on click, only to the player that clicks it, i can get it to work but it will open to everyone in the server. (i dont want mousedetector) what did i do wrong?

function onClicked(hit) local plr = hit.Name local Gplr = game.Players:FindFirstChild(plr)

if Gplr ~= nil then
    local a = game.ServerStorage.test:Clone()
    a.Parent = Gplr.PlayerGui
end

end script.Parent.MouseButton1Click:connect(onClicked)

1 answer

Log in to vote
0
Answered by
ImageLabel 1541 Moderation Voter
9 years ago

There should be no parameters to the MouseButton1Click event's callback function. You can get the player using the LocalPlayer property of Players service from a LocalScript. If you weren't using a LocalScript, you should consider doing so for tasks involving or relying on any sort of input from the client (keyboard, mouse, camera manipulation..).

local player = game.Players.LocalPlayer

function onClicked()
    local playerGui = player:FindFirstChild("PlayerGui")

    if playerGui then
        local gui = "..."
        gui.Parent = player.PlayerGui
    end
end

script.Parent.MouseButton1Click:connect(onClicked)

Note: You would have to use a service other than ServerStorage when using LocalScripts.. because it only replicates to the server. You can use RemoteObjects for client/server communication (getting instances from one to the other) if you really want to keep test in ServerStorage.

Ad

Answer this question