Jump to content

Recommended Posts

my code is like:

local function GetChatterEntitys(player, name, tag)     
    local x, y, z = player.Transform:GetWorldPosition()   
    local ents = TheSim:FindEntities(x, y, z, AROUND_DISTANCE, {name})

[01:04:08]: [string "../mods/workshop-3427829223/scripts/impl.lu..."]:1: bad argument #2 to 'FindEntities' (number expected, got nil) LUA ERROR stack traceback: =[C]:-1 in (method) FindEntities (C) <-1--1> ../mods/workshop-3427829223/scripts/impl.lua:1 in (upvalue) K (Lua) <1-1> u = 141425 - wolfgang (valid:false)

'Is it because the player is valid:false? why is that, it's a client player.

Depending on the context of your player function, If your player is not valid yet, will not get a proper position. This can occur if a player is still loading in/out or is on the player select screen. Try making a ListenForEvent with "playeractivated" for client or "ms_playerjoined" for server.

You could check if your player is valid first before proceeding with the function.

if not player:IsValid() then return end
local x,y,z = player.Transform:GetWorldPosition()

I think a way to not have to check if a player is valid yet is using components, because components are added after a player is valid and have a Transform, I believe.

Edited by oregu
  • Like 1

Thanks! Today I learned. when this happen, the player is in the world, maybe that's because he is loading out? I'll fix it. By the way, 

 TheSim:FindEntities(x, y, z, AROUND_DISTANCE, {name})

is able to be used in server right?

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...