For i,v in paris printing way too many times. How can I avoid this?

It slightly freezes my screen when this runs and then shows it printed (x546). I just want that specific player to be able to walk through when this runs but it breaks and lets anyone through.

WitchEvents.FireCircleLocal.OnClientEvent:Connect(function()

	
	for i,Circle in pairs(game.Workspace:GetChildren()) do
		if Circle.Name == "FireCircle" then
		for i,v1 in pairs(Circle.FireCircle:GetChildren()) do
			for i,v2 in pairs(Circle.Walls:GetChildren()) do
					if Circle.Owner.Value == player.Name then
						print(player)
						v1.CanCollide = false
						v2.CanCollide = false
					end	
				end
			end
		end
	end
end)
1 Like

Have you tried adding a delay, using break or continue?

for i,Circle in workspace:GetChildren do
    if Circle.Name == "FireCircle" then
     for j,v1 in Circle.FireCircle:GetChildren do
         for n,v2 in Circle.Walls:GetChildren() do
           if Circle.Owner.Value == player.Name then
              print("hi "..player)
              continue -- maybe add a Continue?
         end
       end
     end
  end
end

How many times does the “FireCircleLocal” fire to the client.

Says it right here.

Summary

yes

It shouldn’t print (x546) because its and “OnClientEvent”

That doesn’t stop it from being spammed. I’m pretty sure either with a BindableEvent/Function or a RemoteFunction (if I remember correctly) you get an error for spamming

The code should only run once because of the “OnClientEvent”, Unless its fired more than once.

This is what i’m getting now

09:07:03.638 hi Funnyskyswagway3 (x218) - Client - Phasmatos Motus Incendia:41

It only fires once from a server script.

Is there any loops?

text

This is the server script.

local ReplicatedS = game:GetService("ReplicatedStorage")
local CharacterFiles = ReplicatedS.CharacterFiles
local Sounds = CharacterFiles.SoundEffects
local WitchEffects = CharacterFiles.WitchEffects
local WitchEvents = ReplicatedS.CharacterFiles.WitchEvents
local PainEvent = WitchEvents:WaitForChild("phasmatosincendia")
local PainEvent2  = WitchEvents.FireCircleLocal

PainEvent.OnServerEvent:Connect(function(player, mouse)
	local victim = mouse.Parent:FindFirstChild("Humanoid")
	local victimCharacter = mouse.Parent
	local pained = victimCharacter:FindFirstChild("Pained")
	local h = victimCharacter:findFirstChild("Humanoid")
	local Player = victimCharacter
	local Char = victimCharacter
	local victimplayer = game.Players:GetPlayerFromCharacter(victimCharacter)
	local hrp = player.Character:WaitForChild("HumanoidRootPart")
	local effects = game.Lighting
	local vicHRP = victimCharacter.LeftFoot
	
	local CharacterConfig = player.Character:WaitForChild("CharacterConfig")
	CharacterConfig.Magic.Value = CharacterConfig.Magic.Value - 65
	
	local chance = math.random(1,4)
	local soundid = nil

	if chance == 1 then
		soundid = "rbxassetid://6196229813"
	elseif chance == 2 then
		soundid = "rbxassetid://6475304863"
	elseif chance == 3 then
		soundid = "rbxassetid://9817862432"
	elseif chance == 4 then
		soundid = "rbxassetid://rbxassetid://8549979148"
	end


	local Sound = Instance.new("Sound")
	Sound.SoundId = soundid
	Sound.Looped = false
	Sound.RollOffMinDistance = 10
	Sound.RollOffMaxDistance = 100
	Sound.Name = "telekSound"
	Sound.Volume = 3
	Sound.Parent = player.Character.Head
	Sound:Play()
	
	

		
		
	
		
		local ring = WitchEffects.FireCircle:Clone()
		ring.Owner.Value = player.Character.Name
		ring.Parent = game.Workspace
		ring:SetPrimaryPartCFrame(vicHRP.CFrame)
		ring.LightPart.Sound.Playing = true
	
		PainEvent2:FireClient(player)
	
		wait(55)
		ring.LightPart.Sound.Playing = false
		ring:Destroy()
		wait(1)
		Sound:Destroy()	
end)

This is all that’s around when the event is fired so 0 loops.

ring.LightPart.Sound.Playing = true
PainEvent2:FireClient(player)
wait(55)

for i, v in pairs() is a loop.

for example:
if i did

for i, v in pairs(workspace:GetChildren()) do
       print('Hello World!')
end

it print the number of times of how many things are in the workspace.
say, if the workspace had 4 things, it would print 4 times.

1 Like

That shouldn’t be the issue, its going through every single item within a table, it does not repeat if have it fire for a certain item, but in this case @itzF_nny is just getting a object within that table (Assuming its just one), shouldnt repeat

for number,index in pairs(Example:GetChildren()) do
 print(number, index) -- prints every single item
 if index.Name == "Item" then
    print(index) -- should only print the specified item rather than all
end

I totally forgot! I’ll change a few things and come back if there is any problems.

1 Like

09:23:49.956 hi Funnyskyswagway3 (x576) - Client - Phasmatos Motus Incendia:40

This is what I got again.

What do you want your code to do?
What do you want a specific player to be able to walk through?
And what does your workspace look like? (specifically the "FireCircle"s)

  1. The spell you cast clones a model into workspace that traps a character. I want you (The caster) to be able to freely walk through the model while everyone else including the victim (Trapped person) can not.

TVD - Roblox Studio 12_9_2022 9_31_09 AM

I will provide a video example if you don’t understand:
https://www.xbox.com/en-US/play/media/WRAMKK933R

When is the OnClientEvent you sent fired?
If it’s every time when a firecircle is created then you could just fire the event with the created firecircle. Then you only need one loop and no checks to see if they’re the owner.

I found something interesting, when I removed the “FireCircle:GetChildren()” it printed 6 times. (There were 6 items in “Walls”)
image

But when I added it back, it printed 36 times. (Both Walls and FireCircle had 6 items in, but instead of doing 6+6, it did 6 x 6.)

There are actually more parts inside of the fire circle.

TVD - Roblox Studio 12_9_2022 9_41_01 AM
I want that specific player who casted the spell to be able to walk through this.

1 Like