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

4 comments

0

Is this your code? If so, you should know what it does. Otherwise, you should know that ScriptingHelpers.org is not a request site and we will not help you with skidded/stolen code.

0

This is my code

0

And I know what it does??? it legit says it up there ^^^^ it's just not working the game(works perfect in test)

0

this is a free model