Remote Function Help

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? I want my remote function to work.

  2. 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 image

  3. 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)

You can’t use :Connect with remote functions, you have to use

remote.OnServerInvoke = function()
    whatever u want here
end
1 Like

So that is the only thing I did wrong?
Wow,

How does it work with remote events do I use :Connect with it?

You’re using a remote event, but calling events/functions only available for remote functions. RemoteEvent | Roblox Creator Documentation

Use this and it will work:

-- client side
remote:FireServer()

-- server side
remote.OnServerEvent:Connect(function(player)

end)
2 Likes

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

1 Like

Remote events can’t return anything, they’re using a return in her remote function so I don’t think remote events would fit well

1 Like

One more thing, why is the ui not becoming visible after I said to?

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.

1 Like

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)
1 Like