You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? I want my remote function to work.
What is the issue? I am new to remote events and remote functions and I tried coding something that when a player presses a button I want a ui to pop up for everyone saying a "A Player has pressed a button.’ This is the error I’m getting
What solutions have you tried so far? Devfourm
Here are my 2 scripts.
[Local Script]
local remote = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
script.Parent.MouseButton1Click:Connect(function()
remote:InvokeServer()
if game.StarterGui.ScreenGui.TextLabel.Visible == false then
game.StarterGui.ScreenGui.TextLabel.Visible = true
end
end)
[Server Script]
local remote = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
remote.OnServerInvoke:Connect(function()
game.StarterGui.ScreenGui.TextLabel.Text = "Player Has Pressed the Button"
return
game.StarterGui.ScreenGui.TextLabel
end)
Yeah, remote events and bindable events use :Connect since they’re events, remote functions and bindable functions you have to use the thing in my post above
Right, my point is more that they’re using the wrong syntax. Although they really don’t need to use remote functions here, or have a return result. You can change UI using the player passed in the remote event. Using remote events where you can is generally better practice anyway.
You aren’t supposed to reference the TextLabel that’s inside of startergui, you’re supposed to reference the one in PlayerGui in the player object. The objects in StarterGui are replicated to the PlayerGui each time the player respawns so keep that in mind
example:
local Players = game:GetService("Players")
local remote = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
script.Parent.MouseButton1Click:Connect(function()
local playerGui = Players.LocalPlayer.PlayerGui
remote:InvokeServer()
if playerGui.ScreenGui.TextLabel.Visible == false then
playerGui.ScreenGui.TextLabel.Visible = true
end
end)