Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Code works perfectly in test but not in game? Filtering enabled help [closed]

Asked by 5 years ago
Edited 5 years ago

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

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. SmartNode 383 — 5y
0
This is my code Hypoxic1 8 — 5y
0
And I know what it does??? it legit says it up there ^^^^ it's just not working the game(works perfect in test) Hypoxic1 8 — 5y
0
this is a free model User#19524 175 — 5y

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?