Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to access player from ServerScriptService?

Hey, beginner scripter trying to create a GUI that pops up when the player clicks something. If I click it in-game it appears on everyone's screen however I only want it to appear on the player who clicked its screen.

I believe this is because I am accessing the player wrong?

Any help is appreciated.

local ReplicatedStorage = game:WaitForChild("ReplicatedStorage")
local ShiftEvent = game.ReplicatedStorage:WaitForChild("ShiftEvent")
local JobGui = game.Workspace.JobGui.SurfaceGui:WaitForChild("JobButton")
local EndShift = game.StarterGui:WaitForChild("EndShift")
local Players = game:GetService("Players")


Players.PlayerAdded : connect(function(player)

	JobGui.MouseButton1Click:Connect(function(Pressed)
		ShiftEvent:FireClient(player, EndShift)
	
	end)

end)

2 comments

1

oh no- oh no- sorry, I've edited

1

please accept an answer

4 answers

✓ Accepted answer

There is no need for remotes in this case you can have Localscript like this:

local Player = game.Players.LocalPlayer
local JobGui = game.Workspace.JobGui.SurfaceGui:WaitForChild("JobButton")
local EndShift = game.StarterGui:WaitForChild("EndShift")

JobGui.MouseButton1Click:Connect(function()
	-- Do whatever you want
end)




1 comment

0

Cheers mate, looks like I was over complicating it! :P

Make a local script and put this in the text button

script.Parent.MouseButton1Click:Connect(function()
script.Parent.Parent.JobGui.Visible = true
end)

Make sure gui and button got same parent

make the line 8 replaces to this:

Players.PlayerAdded:Connect(function(player)

if this work remember to mark this as the solution or pm me thanks


edit: also this is a local script, this is the full script:

local ReplicatedStorage = game:WaitForChild("ReplicatedStorage")
local ShiftEvent = game.ReplicatedStorage:WaitForChild("ShiftEvent")
local JobGui = game.Workspace.JobGui.SurfaceGui:WaitForChild("JobButton")
local EndShift = game.Players.LocalPlayer:WaitForChild("EndShift") -- we do the EndShift gui to change at the localplayer's gui so thats why I tell you to do a localScript
local Players = game:GetService("Players")


Players.PlayerAdded:Connect(function(player)

    JobGui.MouseButton1Click:Connect(function(Pressed)
        ShiftEvent:FireClient(player, EndShift)

    end)

end)

sorry for the wrong response :P maybe this will work but idk but please mark this as the correct answer if helped, thanks 8)

1 comment

0

thanks for responding, however the GUI still appears on both screen.

On line 8 you have to put:

game.Players.PlayerAdded:Connect(function(player)

This discussion is preserved as it was. New answers, comments, and votes are closed.