Search code examples
luaroblox

Lua - Argument 1 missing or nil


I am trying to make a script that checks for the character, but in my script it says argument 1 missing or nil. Here is my script

local Character

game.Players.PlayerAdded:Connect(function(player)
    Character = player.Character or player.CharacterAdded:Wait()
    print(Character)
end)
if workspace:FindFirstChild(Character) then
    print("CHARACTER FOUND")
end

The error is on line 7.


Solution

  • doing a little digging it seems you can detect at least when the character joins, leaves, and even touches objects. If you can't detect the humanoid directly then you can at least count how many have joined and have left to get the player count.

    if you are in Roblox studio, Roblox studio has many video courses for you to choose from and it looks like this one will answer your question; https://www.youtube.com/watch?v=KGX8LYgZ2og&ab_channel=PrizeCPRoblox

    I might suggest looking at this post here also; How do i create a automatic find player script