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

How to access player from ServerScriptService?

Asked by
TriteA1 30
5 years ago

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.

01local ReplicatedStorage = game:WaitForChild("ReplicatedStorage")
02local ShiftEvent = game.ReplicatedStorage:WaitForChild("ShiftEvent")
03local JobGui = game.Workspace.JobGui.SurfaceGui:WaitForChild("JobButton")
04local EndShift = game.StarterGui:WaitForChild("EndShift")
05local Players = game:GetService("Players")
06 
07 
08Players.PlayerAdded : connect(function(player)
09 
10    JobGui.MouseButton1Click:Connect(function(Pressed)
11        ShiftEvent:FireClient(player, EndShift)
12 
13    end)
14 
15end)
1
oh no- oh no- sorry, I've edited Xapelize 2658 — 5y
1
please accept an answer EnzoTDZ_YT 275 — 5y

4 answers

Log in to vote
0
Answered by
karlo_tr10 1233 Moderation Voter
5 years ago

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

1local Player = game.Players.LocalPlayer
2local JobGui = game.Workspace.JobGui.SurfaceGui:WaitForChild("JobButton")
3local EndShift = game.StarterGui:WaitForChild("EndShift")
4 
5JobGui.MouseButton1Click:Connect(function()
6    -- Do whatever you want
7end)
0
Cheers mate, looks like I was over complicating it! :P TriteA1 30 — 5y
Ad
Log in to vote
1
Answered by 5 years ago

Make a local script and put this in the text button

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

Make sure gui and button got same parent

Log in to vote
0
Answered by
Xapelize 2658 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

make the line 8 replaces to this:

1Players.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:

01local ReplicatedStorage = game:WaitForChild("ReplicatedStorage")
02local ShiftEvent = game.ReplicatedStorage:WaitForChild("ShiftEvent")
03local JobGui = game.Workspace.JobGui.SurfaceGui:WaitForChild("JobButton")
04local 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
05local Players = game:GetService("Players")
06 
07 
08Players.PlayerAdded:Connect(function(player)
09 
10    JobGui.MouseButton1Click:Connect(function(Pressed)
11        ShiftEvent:FireClient(player, EndShift)
12 
13    end)
14 
15end)

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

0
thanks for responding, however the GUI still appears on both screen. TriteA1 30 — 5y
Log in to vote
0
Answered by 5 years ago

On line 8 you have to put:

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

Answer this question