You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

FiveM中出现“attempt to perform arithmetic on a vector3 value”错误的技术求助

Fixing "attempt to perform arithmetic on a vector3 value" Error in FiveM Script

Got it, let's break down what's causing this error and how to fix it.

First, that error message means you're trying to do arithmetic on a vector3 value in a way that FiveM's Lua environment doesn't support. Looking at your code snippet, the problem is almost certainly in this line:

if(#(coords - v.Pos) < v.Size.x) then

Why this happens

coords is a valid vector3 (since it's returned by GetEntityCoords), but if v.Pos from your Config.Zones isn't a proper vector3 object (e.g., it's just a plain Lua table like {x,y,z} instead of being created with vector3(x,y,z)), subtracting coords (a vector3) from v.Pos (a table) will throw that exact error. This breaks the entire loop, so isInMarker and currentZone never get updated—explaining why your markers and menus won't pop up.

How to fix it

1. Fix your Config.Zones definitions

First, check every zone in your Config.Zones to make sure the Pos is defined with vector3(), not a plain table.

Bad Config Example:

Config.Zones = {
    ShopZone = {
        Pos = {45.2, -1023.7, 29.7}, -- Plain table, not vector3
        Size = vector3(3.0, 3.0, 1.5)
    }
}

Good Config Example:

Config.Zones = {
    ShopZone = {
        Pos = vector3(45.2, -1023.7, 29.7), -- Proper vector3 object
        Size = vector3(3.0, 3.0, 1.5)
    }
}

2. If you can't modify the Config (e.g., it's from a shared resource)

If you have to keep v.Pos as a table, convert it to a vector3 right before calculating the distance:

local coords = GetEntityCoords(PlayerPedId())
local isInMarker = false
local currentZone = nil
for k,v in pairs(Config.Zones) do
    -- Convert table to vector3 first (use this if Pos is an indexed table {x,y,z})
    local zonePos = vector3(v.Pos[1], v.Pos[2], v.Pos[3])
    -- OR use this if Pos is a keyed table {x=..., y=..., z=...}
    -- local zonePos = vector3(v.Pos.x, v.Pos.y, v.Pos.z)
    
    if(#(coords - zonePos) < v.Size.x) then
        isInMarker = true
        currentZone = k
    end
end

3. Double-check your Size values

While you're at it, make sure every Size in Config.Zones is a valid vector3 too—you don't want v.Size.x to be a non-numeric value that causes another error later.

Once you fix the v.Pos type issue, the loop will run correctly, update isInMarker and currentZone as expected, and your markers/menus should start working again.

内容的提问来源于stack exchange,提问作者DARTHARAXA

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.28 12:37:46