This code works perfectly in test on roblox studio but not in game. I know it has something to do with filtering enabled and RemoteEvents but i don't know what to do.
the code is meant to make an npc follow another npc and shoot it.
Script location: inside a npc
Not a local script
local players = game.Players:GetChildren() function findNearestTorso(pos) local list = workspace.Zombies:children() local torso = nil local dist = 15 local temp = nil local human = nil local temp2 = nil for x = 1, #list do temp2 = list[x] if (temp2.className == "Model") and (temp2 ~= script.Parent) then temp = temp2:findFirstChild("HumanoidRootPart") human = temp2:findFirstChild("Humanoid") if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then if (temp.Position - pos).magnitude < dist then torso = temp dist = (temp.Position - pos).magnitude end end end end return torso end while true do wait() if script.Parent.Parent.Name == "General" then local target = findNearestTorso(script.Parent.Torso.Position) if target ~= nil then if target.Parent ~= nil then wait(1) script.Parent:SetPrimaryPartCFrame(CFrame.new(script.Parent.Torso.Position, target.position)) if target ~= nil then if target.Parent ~= nil then target.Parent.Humanoid.Health = target.Parent.Humanoid.Health - 1 wait(.1) if target ~= nil then if target.Parent ~= nil then target.Parent.Humanoid.Health = target.Parent.Humanoid.Health - 1 wait(.1) if target ~= nil then if target.Parent ~= nil then target.Parent.Humanoid.Health = target.Parent.Humanoid.Health - 1 end end end end end end end end end end
Thanks in advance
Closed as Not Constructive by User#19524
This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.
Why was this question closed?