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)
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)
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)
On line 8 you have to put:
game.Players.PlayerAdded:Connect(function(player)