Need help with RemoteEvents

I am making a script for my game but I don’t really know how remote event works that much.

the local script is in a text label

Here is the LocalScript:

local True = true
local Count = game.ServerScriptService.PlayerCount

    local ReplicatedStorage = game:GetService("ReplicatedStorage")
    local Event = ReplicatedStorage:WaitForChild("RemoteEvent")



    while wait(0) do
	if Count >= 2 then
		if True == true then
			Event:FireServer(script.Parent.Text, True)
			True = false
		end
		
		
	elseif Count <= 1 then
		if True == true then
			script.Parent.Text = "Waiting For Players..."
			wait(.2)
			script.Parent.Text = "Waiting For Players.."
			wait(.2)
			script.Parent.Text = "Waiting For Players."
			wait(.2)
		end
	end
end

script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local createPartEvent = game.ReplicatedStorage.RemoteEvent

local function EventFired(Text, Value)
	if Value == true then
		print("recieved")
		wait(.5)
		print("GameStarted")
		
		--my code here
	end
end

createPartEvent.OnServerEvent:Connect(EventFired)

Sorry if I ask too much, but I will appreciate if you help!

First parameter of OnServerEvent is always the player who fired the event, so change

local function EventFired(Text, Value)

To

local function EventFired(Player,Text, Value)

You do not have to change your FireServer as it’s passed in automatically

I had another error saying that “FireServer can only be called from the client” sorry for the late response!

To fire a remote event from a script you must do: :FireClient

I got an error saying that “Unable to cast value to Object”?

Because the arguments cannot be empty

it had no errors, but it wont print my message still?

It’s because you set up an OnServerEvent, not an OnClientEvent, so there’s nothing set up whe nyou try ot fire to the client, what are you trying to achieve?

1 Like

From what I’m seeing there seems to be only one issue with your code that needs fixing.

You’re server script code should look something like this:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local createPartEvent = game.ReplicatedStorage.RemoteEvent

createPartEvent.OnServerEvent:Connect(function(player, text, value)
    if value == true then
        print("recieved")
	    wait(.5)
	    print("GameStarted")
	
	    --my code here
	end
end)

For the other issues you might need to include screenshots of your output or additional code bits where any errors occur.

1 Like

it works, thanks for helping out! You deserve a heart!