Search code examples
luaroblox

Roblox - Argument 1 missing or nil


I'm trying to make a script where when you touch a characters hitbox, a certain chat will come up, but the output window says "Argument 1 missing or nil".

Code:

local debounce = false

game.Workspace.RowanAsleep.RowanAsleepHitbox.Touched:Connect(function(hit)  

    if not debounce then
        debounce = true
        if game.Players:GetPlayerFromCharacter(hit.Parent)then
            game.ReplicatedStorage.RowanTalking.RowanSleeping:FireClient()
        end
        wait(2)
        debounce = false
    end
end)

Solution

  • At line 8, FireClient() requires a player instance to be passed. Try making a variable with the result of GetPlayerFromCharacter and pass that into FireClient.

    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player then --GetPlayerFromCharacter will only return nil or a player instance
        game.ReplicatedStorage.RowanTalking.RowanSleeping:FireClient(player)
    end