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

[RE] Function always returns true? [closed]

Asked by 4 years ago

reposted because no one answered first one rip me

I made a camera, For my training game. Now, Hear me out, I am not good at making scripts tidy. What the problem is though: This function always prints true now matter what:

function IsPlrIgnored(HRPN)
    for i,v in pairs(PLRS) do 
        if HRPN == v then
            print(v)
            return false
        end
    end
    return true
end

I implemented this for a bug. Its a weird bug, When two players stand next to eachother, One in the group and not in the group, The camera will target the player in the group. This is not what i want. This happens randomly. Idk what to do. Can someone fix this VERY broken script?

local RS = game:GetService("ReplicatedStorage")
local RS2 = game:GetService("RunService")
local DB = false

local Barrel = script.Parent
local Decal = Barrel.Parent.Parent.Screen.Screen.Decal
local CON = script.Parent.Parent.Configuration

local fireRate = CON.Rate.Value
local aggroDist = CON.DetectionDistance.Value
local IgnoreList = {Barrel}
PLRS = {}
--------------------------------
wait(3)
function checkIfInGroupAndGroupRank(PLR)
    if PLR then
        if PLR:IsInGroup(CON.Group.Value) and CON.Group.Value ~= 0 then
            if PLR:GetRankInGroup(CON.Group.Value) > CON.GroupRank.Value and CON.GroupRank.Value ~= 0 then
                print("True")
                return true
            end
        end
    end
    print("False")
    return false
end

function checkIfInGroupAndGroupRankAll()
    for i,v in pairs(game.Players:GetChildren()) do
        local iigagr = checkIfInGroupAndGroupRank(v)
        if iigagr == false then
            table.insert(PLRS, v)
        end
    end
end

function IsPlrIgnored(HRPN)
    for i,v in pairs(PLRS) do 
        if HRPN == v then
            print(v)
            return false
        end
    end
    return true
end

checkIfInGroupAndGroupRankAll()
--------------------------------
while wait(fireRate) do
    wait()
    script.Parent.Mesh.TextureId = "http://www.roblox.com/asset/?id=2093097"
    Decal.Transparency = 0
    local target = nil
    for i, v in pairs(game.Workspace:GetChildren()) do
        local human = v:FindFirstChild("Humanoid")
        HRP = v:FindFirstChild("HumanoidRootPart")
        if human and HRP and human.Health > 0 then
            if (HRP.Position - Barrel.Position).magnitude < aggroDist then
                local ray = Ray.new(Barrel.Position, (HRP.Position - Barrel.Position).Unit * aggroDist)
                local hit, Position = game.Workspace:FindPartOnRayWithIgnoreList(ray , IgnoreList)
                if hit.Parent == human.Parent or hit.Parent.Parent == human.Parent then
                    target = HRP
                else
--                  print("Blocked "..hit.Name)
                end
                if hit.Transparency == 1 then
                    table.insert(IgnoreList, hit)
                end
            end
        end
    end
    if target then
        print(target.Parent.Name)
        local IsPlrIgnored1 = IsPlrIgnored(target.Parent.Name)
        print(IsPlrIgnored1)
        if IsPlrIgnored1 == true then
            local HRP = target
            Decal.Transparency = 1
            script.Parent.Mesh.TextureId = "http://www.roblox.com/asset/?id=4989331700"
            Barrel.CFrame = CFrame.new(Barrel.Position, HRP.Position)
        end
    end
end

REMEMBER: No errors in output and, MAKE A GOOD ANSWER! Tell me why, How to prevent this kind of stuff happening, AND FIRST LOOKING AT THE QUESTION!!!

0
i dont know you_success -50 — 4y
3
Try changing line 39 to "if HPRN == v.Name then." You can't compare a string to a userdata. y3_th 176 — 4y
0
Ill try hasanchik 49 — 4y
0
INSTANT UPVOTE WHY IS THIS NOT A ANSWER hasanchik 49 — 4y

Locked by youtubemasterWOW and JesseSong

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?