Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Client event not firing. Returning error. Any help?

Asked by
AZDev 590 Moderation Voter
8 years ago

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

Log in to vote
1
Answered by 8 years ago

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.

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. AZDev 590 — 8y
Ad

Answer this question