Hello Developers,
I’m currently working on a game and I’m hitting a problem.
I’ve tried searching everywhere on the forums, YouTube and Roblox developer pages but I can’t seem to find anything regarding my issue.
Any and all help is very much appreciated!
In my game there’s a certain part (this part can appear multiple times), this part has a basic collide script in it which detects if the NPC’s I made walk through it. This works fine, I made it so it only triggers upon colliding with the HumanoidRootPart and also doesn’t trigger while the effect is already working.
However, I want to add a “queue” like system to this script. So if 2 NPC’s walk through the part, it happens twice! (In a row not at once.)
This did not work the way I thought it would, I understand exactly why, but I don’t know what to do to actually get what I need.
Because, as I’m sure most of you could have guessed, now that I added this queue both NPC’s their HumanoidRootParts get added to the queue multiple times. Resulting in this effect happening 20 to 90 times in a row instead of twice in a row.
I have no clue how I can script it so both HumanoidRootParts only get added once, BUT can still be added to another version of this part if they then walk through that one.
This is the script:
local unit = script.Parent.Parent
function ot(hit)
if hit.Parent.Parent:IsA("Folder")then
--print(hit.Name)
local h = hit.Parent:FindFirstChild("Humanoid")
if h ~= nil then
if h.Health ~= 0 then
--print(h.Name)
if hit.Parent.Player.Value ~= unit.Player.Value then
if hit.Name == "HumanoidRootPart" then
unit.InRange.Value = unit.InRange.Value+1
if unit.Attacking.Value == false then
unit.Attacking.Value = true
--print(hit.Parent.Name)
-- HERE IS WHERE THE EVENT HAPPENS BUT REMOVED BECAUSE NOT IMPORTANT FOR FORUM
unit.InRange.Value = unit.InRange.Value-1
unit.Attacking.Value = false
end
end
end
end end end end
script.Parent.Touched:connect(ot)
I’m not sure if the script is of any use because my only real problem is that it runs too many times. The script itself (after many bugs) now works flawless.
If I place the “InRange” value after the “Attacking” value it won’t run more then once (and prevents the second NPC to run it/be added to the queue/InRange value) but then again, I don’t want it to run once, I want it to run once per unique unit that walked through.
I hope this is clear, if not, please ask! And thanks a lot in advance!