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

Check if there is only 1 model with the name, if not set one of the model's humanoid.health to 0?

Asked by 3 years ago
Edited 3 years ago

can someone fix this for me? what i want it to be like is check if in game.Workspace.Map.Enemy if there is a model named "EvilDefense" check the amount of the model if there is more then 1 model in the folder "Enemy" set one of the model's humanoid.health to 0, the script is in the model.

local children = game.Workspace.Map.Enemy.EvilDefense:GetChildren()
local count = #children

local BossCount = 0

for Index, Object in next, children do
if (Object:IsA("Model") and (Object.Name == "EvilDefense")) then
BossCount = (BossCount + 1)

if BossCount ~= 1 then
script.Parent.Humanoid.Health = 0
end

print(BossCount) 
end
end

1 answer

Log in to vote
0
Answered by 3 years ago

I check the script and its not going trough the loop so I made this:

local tests = game.Workspace:WaitForChild("Test"):GetChildren()

local boss = 0

for i, test in pairs(tests) do -- I used pairs instead of next lol
    if test.Name == "EvilDefense" then
        if test:IsA("Model") then
            boss = boss + 1

            if boss ~= 1 then
                script.Parent.Health = 0
                print("Killed")
            end
            print(boss) -- prints the boss number value
        end
    end
end

this script I made was inside the humanoid but I suggest putting it in the serverscriptservice or somewhere else :) hope I helped LOL

0
man why I cant log in roblox lol acediamondn123 147 — 3y
Ad

Answer this question