Help with while true do

local Part = script.Parent

while true do wait()
	local Check = workspace:GetPartsInPart(Part)
	local Active = true

	for i, v in ipairs(Check) do
		if v.Parent:FindFirstChildOfClass("Humanoid") then
			local Humanoid = v.Parent:FindFirstChild("Humanoid")
			if v.Name == "HumanoidRootPart" or Humanoid then
				local Player = game.Players:GetPlayerFromCharacter(v.Parent)
				local Damage = Player:WaitForChild("DamageActive")
				if Damage then
					if Damage.Value == true then
						Active = false
						game.Players:GetPlayerFromCharacter(v.Parent).DamageActive.Value = Active
						v.Parent.Humanoid:TakeDamage(25)
						print("Hit")
						wait(1)
						Active = true
						if Damage then
							Damage.Value = Active
						end
					elseif Damage.Value == false then
						wait(1)
						Damage.Value = true
					end
				end
			end
		end
	end
end
local Part = script.Parent

while true do wait()
	local Check = workspace:GetPartsInPart(Part)
	local Active = true

	for i, v in ipairs(Check) do
		if v.Parent then
			local Humanoid = v.Parent:FindFirstChild("Humanoid")
			if Active then
				Active = false
				v.Parent.Humanoid:TakeDamage(25)
				wait(1)
			end
		end
	end
end

At first I thought that the “Active” being in the script is the reason why if there’s more than 1 Character touching the Part, it only damages 1 Character and the other Character will only be able to take damage if the other Character is removed from the Part. ← That is the problem I’m having. Also I don’t want to use Part.Touched as it’s inconsistent. Y’all got any idea how to solve this problem? :cry: :cold_sweat: :roll_eyes:
Pwease help :point_right: :point_left: :flushed: :people_hugging:

while true do wait(1)
	script.Parent.RemoteEvent:FireServer()
end
script.Parent.RemoteEvent.OnServerEvent:Connect(function(Player)
	local Active = true
	
	local Part = workspace.DamageTest
	local Check = workspace:GetPartsInPart(Part)
	for i, v in ipairs(Check) do
		if v.Parent then
			if v.Parent.Name == Player.Name then
				print("Same")
				local Humanoid = v.Parent:FindFirstChild("Humanoid")
				if Active then
					Active = false
					Humanoid:TakeDamage(25)
					wait(1)
				end
			end
		end
	end
end)

This is a kinda goofy solution, I’d like a better one plz!

The wait(1) halts the whole script, meaning that any other player in the part won’t be detected because the loop is halted. Without Part.Touched, things will get complicated and inefficient. You can have a table of tables, with each small table having a player name and a cooldown value. Each cooldown value would be subtracted from every frame.

1 Like

Cool, cool. Can I get your opinion on this?

Using a player script is definitely better for the method you want. If it works, it works.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.