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

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)
1
oh no- oh no- sorry, I've edited Xapelize 2658 — 4y
1
please accept an answer EnzoTDZ_YT 275 — 4y

4 answers

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

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)




0
Cheers mate, looks like I was over complicating it! :P TriteA1 30 — 4y
Ad
Log in to vote
1
Answered by 4 years ago

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

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

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)

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

On line 8 you have to put:

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

Answer this question