How do I open a gui for a local player using a server script?

Hi, I am trying to get a gui to open for a local player when they click a part but I am not sure how.
This is my code for my server script so far:
image

This doesn’t make sense because server scripts take server based scripts your trying to do this for a local player.

1 Like

The LocalPlayer property of Players is nil on the server. It doesn’t exist. You’d have to get the player from the argument of the clickdetector’s MouseClick event. Then use this argument (player) when firing the client.

So you’d do

game.ReplicatedStorage.OpenShirtGUI:FireClient(player)

Then create a listener on the client.

local myEvent = game:GetService('ReplicatedStorage').OpenShirtGUI
local myGui = shirtGui -- Just place this wherever your ShirtGUI is

myEvent.OnClientEvent:Connect(function()
    myGui.Visible = true
end)

On a side note, ensure you’re using :GetService on your services as sometimes they will return nil, thus returning an error.

So instead of game.Players, you’d do game:GetService('Players')

The one exemption from this is the workspace, there’s already a global variable called workspace which you can use to get to the workspace.

4 Likes

Thank you! This helped me understand it a lot better! How do I go about getting the player via the MouseClick event?

It’s returned as the first argument of the clickdetector

So in your case

script.Parent.ClickDetector.MouseClick:Connect(function(player--[[Here]])

Thank you so much! It now works :slight_smile: .

3 Likes