weire Posted March 30, 2025 Share Posted March 30, 2025 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. Link to comment https://forums.kleientertainment.com/forums/topic/165129-got-nil-from-local-x-y-z-playertransformgetworldposition/ Share on other sites More sharing options...
weire Posted March 30, 2025 Author Share Posted March 30, 2025 is it because the GetWorldPosition and FindEntities is working on client? How do we know if a function is working on server of client? it confuse me a lot Link to comment https://forums.kleientertainment.com/forums/topic/165129-got-nil-from-local-x-y-z-playertransformgetworldposition/#findComment-1809963 Share on other sites More sharing options...
oregu Posted April 4, 2025 Share Posted April 4, 2025 (edited) 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 April 4, 2025 by oregu 1 Link to comment https://forums.kleientertainment.com/forums/topic/165129-got-nil-from-local-x-y-z-playertransformgetworldposition/#findComment-1810860 Share on other sites More sharing options...
Rickzzs Posted April 5, 2025 Share Posted April 5, 2025 you should check the validity from Transform because it returns nil for unconstructed and (0,0,0) for deconstructed object. 1 Link to comment https://forums.kleientertainment.com/forums/topic/165129-got-nil-from-local-x-y-z-playertransformgetworldposition/#findComment-1810926 Share on other sites More sharing options...
weire Posted April 5, 2025 Author Share Posted April 5, 2025 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? Link to comment https://forums.kleientertainment.com/forums/topic/165129-got-nil-from-local-x-y-z-playertransformgetworldposition/#findComment-1810946 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now