Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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

1 comment

0

man why I cant log in roblox lol

This discussion is preserved as it was. New answers, comments, and votes are closed.