Hello all, I am new to Roblox creating and programming. I have been using a lot of the pre-made models and stuff to kind of get in touch with the language and customizing them. I just started on the 11th and have learned so much already but am really new still. I have spent hours googling and searching for my issue. I have these 2 enemies that use the same "jeff the killer" script. The issue is they basically attack other bad guys or deer I have in the game. They completely ignore the player.
Can someone please point me in the right direct. I know this is prolly a stupid easy issue that I am just too dumb to see. Thanks for any help at all. The code main code for the enemy is here:
local JeffTheKillerScript = script
repeat
Wait(0)
until JeffTheKillerScript and JeffTheKillerScript.Parent and JeffTheKillerScript.Parent.ClassName == "Model" and
JeffTheKillerScript.Parent:FindFirstChild("Head") and
JeffTheKillerScript.Parent:FindFirstChild("Torso")
local JeffTheKiller = JeffTheKillerScript.Parent
function raycast(Spos, vec, currentdist)
local hit2, pos2 = game.Workspace:FindPartOnRay(Ray.new(Spos + (vec * .05), vec * currentdist), JeffTheKiller)
if hit2 ~= nil and pos2 then
if
hit2.Name == "Handle" and not hit2.CanCollide or
string.sub(hit2.Name, 1, 6) == "Effect" and not hit2.CanCollide
then
local currentdist = currentdist - (pos2 - Spos).magnitude
return raycast(pos2, vec, currentdist)
end
end
return hit2, pos2
end
function RayCast(Position, Direction, MaxDistance, IgnoreList)
return Game:GetService("Workspace"):FindPartOnRayWithIgnoreList(
Ray.new(Position, Direction.unit * (MaxDistance or 999.999)),
IgnoreList
)
end
--
--
--
--[[if JeffTheKillerScript and JeffTheKiller and JeffTheKiller:FindFirstChild("Thumbnail")then]] --[[JeffTheKiller:FindFirstChild("Thumbnail"):Destroy();]] --[[end;]] local JeffTheKillerHumanoid
for _, Child in pairs(JeffTheKiller:GetChildren()) do
if Child and Child.ClassName == "Humanoid" and Child.Health ~= 0 then
JeffTheKillerHumanoid = Child
end
end
local AttackDebounce = false
local JeffTheKillerKnife = JeffTheKiller:FindFirstChild("Knife")
local JeffTheKillerHead = JeffTheKiller:FindFirstChild("Head")
local JeffTheKillerHumanoidRootPart = JeffTheKiller:FindFirstChild("HumanoidRootPart")
local WalkDebounce = false
local Notice = true
local JeffLaughDebounce = false
local MusicDebounce = false
local NoticeDebounce = false
local ChosenMusic
function FindNearestBae()
local NoticeDistance = 100
local TargetMain
for _, TargetModel in pairs(Game:GetService("Workspace"):GetChildren()) do
if
JeffTheKillerScript and JeffTheKiller and JeffTheKillerHumanoid and JeffTheKillerHumanoid.Health ~= 0 and
TargetModel.className == "Model" and
TargetModel ~= JeffTheKiller and
TargetModel.Name ~= JeffTheKiller.Name and
TargetModel:FindFirstChild("Torso") and
TargetModel:FindFirstChild("Head")
then
local TargetPart = TargetModel:FindFirstChild("Torso")
local FoundHumanoid
for _, Child in pairs(TargetModel:GetChildren()) do
if Child and Child.ClassName == "Humanoid" and Child.Health ~= 0 then
FoundHumanoid = Child
end
end
if
TargetModel and TargetPart and FoundHumanoid and FoundHumanoid.Health ~= 0 and
(TargetPart.Position - JeffTheKillerHumanoidRootPart.Position).magnitude < NoticeDistance
then
TargetMain = TargetPart
NoticeDistance = (TargetPart.Position - JeffTheKillerHumanoidRootPart.Position).magnitude
local hit, pos =
raycast(
JeffTheKillerHumanoidRootPart.Position,
(TargetPart.Position - JeffTheKillerHumanoidRootPart.Position).unit,
500
)
if
hit and hit.Parent and hit.Parent.ClassName == "Model" and hit.Parent:FindFirstChild("Torso") and
hit.Parent:FindFirstChild("Head")
then
if
TargetModel and TargetPart and FoundHumanoid and FoundHumanoid.Health ~= 0 and
(TargetPart.Position - JeffTheKillerHumanoidRootPart.Position).magnitude < 9 and
not AttackDebounce
then
Spawn(
function()
AttackDebounce = true
local SwingAnimation =
JeffTheKillerHumanoid:LoadAnimation(JeffTheKiller:FindFirstChild("Swing"))
local SwingChoice = math.random(1, 2)
local HitChoice = math.random(1, 3)
SwingAnimation:Play()
SwingAnimation:AdjustSpeed(1.5 + (math.random() * 0.1))
if
JeffTheKillerScript and JeffTheKiller and JeffTheKillerKnife and
JeffTheKillerKnife:FindFirstChild("Swing")
then
local SwingSound = JeffTheKillerKnife:FindFirstChild("Swing")
SwingSound.Pitch = 1 + (math.random() * 0.04)
SwingSound:Play()
end
Wait(0.3)
if
TargetModel and TargetPart and FoundHumanoid and FoundHumanoid.Health ~= 0 and
(TargetPart.Position - JeffTheKillerHumanoidRootPart.Position).magnitude < 8
then
FoundHumanoid:TakeDamage(30)
if
HitChoice == 1 and JeffTheKillerScript and JeffTheKiller and JeffTheKillerKnife and
JeffTheKillerKnife:FindFirstChild("Hit1")
then
local HitSound = JeffTheKillerKnife:FindFirstChild("Hit1")
HitSound.Pitch = 1 + (math.random() * 0.04)
HitSound:Play()
elseif
HitChoice == 2 and JeffTheKillerScript and JeffTheKiller and JeffTheKillerKnife and
JeffTheKillerKnife:FindFirstChild("Hit2")
then
local HitSound = JeffTheKillerKnife:FindFirstChild("Hit2")
HitSound.Pitch = 1 + (math.random() * 0.04)
HitSound:Play()
elseif
HitChoice == 3 and JeffTheKillerScript and JeffTheKiller and JeffTheKillerKnife and
JeffTheKillerKnife:FindFirstChild("Hit3")
then
local HitSound = JeffTheKillerKnife:FindFirstChild("Hit3")
HitSound.Pitch = 1 + (math.random() * 0.04)
HitSound:Play()
end
end
Wait(0.1)
AttackDebounce = false
end
)
end
end
end
end
end
return TargetMain
end

2 comments
Please tell me this code wasn't written by you. I commend the effort, but its a mess. The answer below states your problem, the second you suggested seems like the appropriate place of application.
Thank you very much I will play with this shortly. Nah the code wasn't written by me. I have been using shared models / scripts I find in the studio database to try learning. This code was indeed a mess, like horribly, Prolly why I am having such a hard time making heads and tails of it but it's for a freddy kruiger enemy that my fiance is in love with so I am trying hard to get it to work. Thanks