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.
01 | local ReplicatedStorage = game:WaitForChild( "ReplicatedStorage" ) |
02 | local ShiftEvent = game.ReplicatedStorage:WaitForChild( "ShiftEvent" ) |
03 | local JobGui = game.Workspace.JobGui.SurfaceGui:WaitForChild( "JobButton" ) |
04 | local EndShift = game.StarterGui:WaitForChild( "EndShift" ) |
05 | local Players = game:GetService( "Players" ) |
06 |
07 |
08 | Players.PlayerAdded : connect( function (player) |
09 |
10 | JobGui.MouseButton 1 Click:Connect( function (Pressed) |
11 | ShiftEvent:FireClient(player, EndShift) |
12 |
13 | end ) |
14 |
15 | end ) |
There is no need for remotes in this case you can have Localscript
like this:
1 | local Player = game.Players.LocalPlayer |
2 | local JobGui = game.Workspace.JobGui.SurfaceGui:WaitForChild( "JobButton" ) |
3 | local EndShift = game.StarterGui:WaitForChild( "EndShift" ) |
4 |
5 | JobGui.MouseButton 1 Click:Connect( function () |
6 | -- Do whatever you want |
7 | end ) |
Make a local script and put this in the text button
1 | script.Parent.MouseButton 1 Click:Connect( function () |
2 | script.Parent.Parent.JobGui.Visible = true |
3 | end ) |
Make sure gui and button got same parent
make the line 8 replaces to this:
1 | 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:
01 | local ReplicatedStorage = game:WaitForChild( "ReplicatedStorage" ) |
02 | local ShiftEvent = game.ReplicatedStorage:WaitForChild( "ShiftEvent" ) |
03 | local JobGui = game.Workspace.JobGui.SurfaceGui:WaitForChild( "JobButton" ) |
04 | 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 |
05 | local Players = game:GetService( "Players" ) |
06 |
07 |
08 | Players.PlayerAdded:Connect( function (player) |
09 |
10 | JobGui.MouseButton 1 Click:Connect( function (Pressed) |
11 | ShiftEvent:FireClient(player, EndShift) |
12 |
13 | end ) |
14 |
15 | 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)
On line 8 you have to put:
1 | game.Players.PlayerAdded:Connect( function (player) |