Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

attempt to compare Vector3 and number? Why is this?

Asked by 4 years ago

So I got the error Attempt to compare Vector3 And Number but I do not know why, I have seen many other people use what I am using but they do not get this error! I am trying to modify a tutorial and I was doing good until I had to use magnitude! Entire Script:

local UpdatePosition = 0.06 --How long it takes target the next humanoid
local DamageTime = 3 --How long it takes for the enemy to attack again
local Damage = 30 --How much damage the enemy does
--Advanced Config
local AgroDist = 101
local HitBox = script.Parent.HitBox 
local Player = game.Players.LocalPlayer
local enhum = script.Parent.Enemy
local ddb = false
local character

while wait() do
    local player = game.Players.LocalPlayer
    for i, v in pairs(game.Players:GetChildren()) do
     character = game.Workspace:WaitForChild(v.name)
        if (character.Humanoid.RootPart.Position - enhum.RootPart.Position) <= AgroDist then
            enhum:MoveTo(character.PrimaryPart.Position)
            enhum.MoveToFinished:Wait(UpdatePosition)
        end
        end



What's wrong with my code?

1 answer

Log in to vote
0
Answered by
Raccoonyz 1092 Donator Moderation Voter
4 years ago

You forgot to add .Magnitude. A correct version would be like this:

local UpdatePosition = 0.06 --How long it takes target the next humanoid
local DamageTime = 3 --How long it takes for the enemy to attack again
local Damage = 30 --How much damage the enemy does
--Advanced Config
local AgroDist = 101
local HitBox = script.Parent.HitBox
local Player = game.Players.LocalPlayer
local enhum = script.Parent.Enemy
local ddb = false
local character

while wait() do
    local player = game.Players.LocalPlayer
    for i, v in pairs(game.Players:GetChildren()) do
        character = game.Workspace:WaitForChild(v.name)
        if (character.Humanoid.RootPart.Position - enhum.RootPart.Position).Magnitude <= AgroDist then
            enhum:MoveTo(character.PrimaryPart.Position)
            enhum.MoveToFinished:Wait(UpdatePosition)
        end
    end
end

0
beginner mistake sorry, But Thanks! I have another error now but I can hopefully get help fixing that. allybally12345 40 — 4y
Ad

Answer this question