Recasting weird error

I was following a devking tutorial on “Recasting” and this happens when I run the script
video:


Npc Overhead gui script(I dont think this would cause the baseplate to turn into a treadmill)

Raycasting script:

so instead of the turret killing the npc the baseplate turns into a treadmill LOL

1 Like

script:
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local bullet = ReplicatedStorage:WaitForChild(“Bullet”)

local turret = script.Parent

local fireRate = 0.5
local bulletDamage = 10
local bulletSpeed = 150
local aggroDist = 100

while wait(fireRate) do

-- Find the target,Detect if realist to shoot
local target = nil
for i, v in pairs(game.Workspace:GetChildren()) do
	local human = v:FindFirstChild("Humanoid")
	local torso = v:FindFirstChild("Torso")
	if human and torso and human.Health > 0 then
		if (torso.Position - turret.Position).magnitude < aggroDist then 
			
			local bulletRay = Ray.new(turret.Position,(torso.Position - turret.Position).Unit * aggroDist)
			local hit,position = game.Workspace:FindPartOnRayWithIgnoreList(bulletRay, {turret})
			if hit == torso then
				target = torso
			else
				print("Object in way")
			end
			
			
		end
	end
end
if target then
	local torso = target
	turret.CFrame = CFrame.new(turret.Position, torso.Position)
	
	local newBullet = bullet:Clone(bullet)
	newBullet.Position = turret.Position
	newBullet.Parent = game.Workspace
	
	newBullet.Velocity = turret.CFrame.LookVector * bulletSpeed	
	
	newBullet.Touched:Connect(function(objectHit)
		local human = objectHit.Parent:FindFirstChild("Humanoid")
		if human then
			human:TakeDamage(bulletDamage)
		end
	end)
end

end

That tutorial by “TheDevKing” is outdated, use this tutorial instead:

I learned how to ray cast with that very tutorial.

1 Like

lol thank you this is very much appreciated

1 Like

Remember to mark the reply that solved the issue as the solution!