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)
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.