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

RayCasting Does not work. And I am posting this to get help What is wrong with the script?

21:30:06.346 - Workspace.Part.Part.Script:17: attempt to compare userdata and number

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Bullet = ReplicatedStorage:WaitForChild("Bullet")


local turrent = script.Parent
local Firerate = 0.2
local BulletDamage = 1
local BulletSpeed = 200
local AggroDistance = 100
local target 
while wait(Firerate)do
	local target = nil
	for i, v in pairs (game.Workspace:GetChildren()) do
		local humanoid = v:FindFirstChild("Humanoid")
		local HumanoidRootPart = v:FindFirstChild("HumanoidRootPart")
		if humanoid and HumanoidRootPart and humanoid.Health > 0 then
			if (HumanoidRootPart.Position - turrent.Position) < AggroDistance then
				humanoid = target
			end
		end
	end
end

1 answer

Replace Line 17 with this code as you forgot to include magnitude in your if statement.

if (HumanoidRootPart.Position - turrent.Position).magnitude < AggroDistance then

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