For I,V loops not working properly

Hi everyone first time posting here. Anyways you can correct me on how I posted this after but I got an annoying problem that ive been tryna fix for sometime now by going through different approaches but still getting problems at the end of each approach.

Am tryna make a burning damage system for when the enemies (NPCs) touch the hitboxes. What I’ve done is put the particle emitter in the NPCs bodies before hand (this was a changed from just replicating it from replicated storage), make a local function which checks if the enemy is on the Whitelist before being hit, loop for HumanoidRootPart then damage the NPC upon the loop finding HRP, have another loop which will check for the Particles inside the NPCs and emit them and then finally add the hit NPC in Whitelist table

Now running this once works perfectly fine, but running it multiple times (by calling it multiple times after clearing the Whitelist table) makes the script do way more damage than its supposed to


Thats the local function^

Thats where I call the local function^
image
Whitelist script^

The Output^

1 Like


This is Touched Event that clears the whitelist btw

1 Like

Try clearing the whitelist when the damagingpart2.Touched event starts.

damagingpart2.Touched:Connect(function(hit)
    Whitelist2 = {}
    Damage2(hit)
    task.wait(1)
    Whitelist2 = {}
    Damage2(hit)
    task.wait(1)
    Whitelist2 = {}
    Damage2(hit)
end)


Didnt seem to work.

It had to be inside the loop considering its a condition that has to be met

The problem is that when i remove the task.wait(1) in the .Touched event function and just make it damage the player once, it works perfectly. But if i run it multiple times, it doesnt

Maybe it’s because there are multiple threads checking to damage the player, and these threads are all trying to damage the player after each other in 1 second bursts.
Try adding a damage cooldown, or use CollectionService to tag the player whether they’re on fire or not.

Could you give me a template of how I could use CollectionService please

It works like this:

local collectionService = game:GetService("CollectionService")
local part = nil -- This can be any instance

collectionService:AddTag(part, "Burning") -- Adds a tag to part
collectionService:HasTag(part, "Burning") -- Checks if a tag exists on part
collectionService:RemoveTag(part, "Burning") -- Removes a tag from part
1 Like

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