Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Client event not firing. Returning error. Any help?

This script is just a draft.

I am receiving this error Argument 1 missing or nil for line 41

local waitingforplayerstime = 20
local waitingforplayers = waitingforplayerstime -- for consistency throughout script
local intermission = 5
local matchtime = 120 -- 2 minutes

local numofplayers = 0
local maxplayers = 3 -- max number of players in game

local ss = game:WaitForChild("ServerStorage")	--Use waitforchild to prevent errors
local rs = game:WaitForChild("ReplicatedStorage")

local events = {}

local players = game:WaitForChild("Players")

players.PlayerAdded:connect(function()
	print("PlayerAddedTest Passed")
	print(numofplayers)
	numofplayers = numofplayers + 1
	print(numofplayers)
	wait(1)
	initiatematch()
end)

players.PlayerRemoving:connect(function()
	print("PlayerRemovedTest Passed")
	numofplayers = numofplayers - 1
end)

function initiatematch()
	if numofplayers > 1 then
		while waitingforplayers > 0 do
			waitingforplayers = waitingforplayers - 1
			print(waitingforplayers)
			if numofplayers < 2 then
				waitingforplayers = waitingforplayerstime -- stop the deployment of players if there is only 1 player in-game
				break
			end
		end
		if waitingforplayers <= 0 then
			game.ReplicatedStorage.TeamColor:FireClient() -- error here
		end
	end
end

The script is located in serverscriptservice The client event being fired is located in playerscripts The code for the client event is just a print statement to make sure the event has fired and been received. FE is not enabled.

1 answer

✓ Accepted answer

The FireClient method requires a Player object to be passed as its first argument to fire for that player. You may however want to use the FireAllClients method if you want the event to fire for all players.

1 comment

0

I ended up not using an event at all but this does work. I figured out that I could set the players TeamColor in a ServerScript and didn't need an event at all. Thanks anyway.

This discussion is preserved as it was. New answers, comments, and votes are closed.