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

Why does my script have "Argument 1 missing or nil?"

This is my script, line 6 is what the output complains about

for i, v in pairs(game.Players:GetPlayers()) do
	if v.TeamColor == BrickColor.new("Bright red") then
		if v:FindFirstChild("PlayerGui") then	
       			v.Character.Humanoid.HealthChanged:connect(function() 
				print("Boss Health Changed")
        			v.PlayerGui.BossHealth.Healthbar.LocalScript.RemoteEvent:FireClient() 
				print('Fired')
 			end)
		end
    end
end

I created this script so that if someone's health from the Bright red team is altered/changed (by use of that HealthChanged function) it is going to fire a remote event to the client. Why is it saying the argument is nil?

1 comment

0

Please Accept my Answer

1 answer

Whenever using FireClient, which is used in a Server Script, you need to fill out the first 'argument', or the word in the parenthesis, with the player's name, so that it will fire that specific client. If you're firing all clients, you can ignore the player name, and instead use FireAllClients.

for i, v in pairs(game.Players:GetPlayers()) do
    if v.TeamColor == BrickColor.new("Bright red") then
        if v:FindFirstChild("PlayerGui") then   
                v.Character.Humanoid.HealthChanged:connect(function() 
                print("Boss Health Changed")
                    v.PlayerGui.BossHealth.Healthbar.LocalScript.RemoteEvent:FireClient(v) 
                print('Fired')
            end)
        end
    end
end

3 comments

0

So it would be v.Name, not just v.

1

And also, there isn't much need for your RemoteEvent to be in the PlayerGui? I dunno, just saying.

1

Wrong, it should be the player's Player object; not its name.

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