Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

attempt to compare Vector3 and number? Why is this?

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

✓ Accepted answer

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

1 comment

0

beginner mistake sorry, But Thanks! I have another error now but I can hopefully get help fixing that.

This discussion is preserved as it was. New answers, comments, and votes are closed.