I am checking if they already have a folder for their effects, yet the script can’t :GetChildren() (later on in the code)
Code:
if not game.Workspace:FindFirstChild(player.Name.." Effects") then
local Effects = Instance.new("Folder", workspace)
Effects.Name = player.Name.." Effects"
Debris:AddItem(Effects,DeathMagicDuration)
else
local Effects = game.Workspace:FindFirstChild(player.Name.." Effects")
end
When do you call GetChildren, inside the if check or outside of it?
We need a little bit more context, the code you’re previewing us should be functional, except the else statement where you are setting a local variable and not using it?
2 things, it is a magic handler, and each magic remote checks for the folder, and yes I am calling that but I didn’t make the folder outside of the remote events for the magic because I don’t have the player so I just thought creating them as they get fired, and keeping the folder for other magic
if not game.Workspace:FindFirstChild(player.Name.." Effects") then
local Effects = Instance.new("Folder", workspace)
Effects.Name = player.Name.." Effects"
Debris:AddItem(Effects,DeathMagicDuration)
else
local Effects = game.Workspace:FindFirstChild(player.Name.." Effects")
end
local Center = DeathMagicMeshes:WaitForChild("Center"):Clone()
Center.CFrame = Humrp.CFrame * CFrame.new(0,11.5,-20)
Center.Orientation = Center.Orientation + Vector3.new(90,0,0)
Center.Size = Vector3.new(.75,.75,29)
Center.Parent = Effects
local Wave1 = DeathMagicMeshes:WaitForChild("Wave1"):Clone()
Wave1.CFrame = Center.CFrame * CFrame.new(0,0,13.2)
Wave1.Orientation = Wave1.Orientation - Vector3.new(90,0,0)
Wave1.Size = Vector3.new(1,.1,1)
Wave1.Parent = Effects
local Wave2 = DeathMagicMeshes:WaitForChild("Wave2"):Clone()
Wave2.CFrame = Center.CFrame * CFrame.new(0,0,11)
Wave2.Orientation = Wave2.Orientation - Vector3.new(90,0,0)
Wave2.Size = Vector3.new(1,.1,1)
Wave2.Parent = Effects
spawn(function()
local tempCount = 0
while wait(1) do
tempCount = tempCount + 1
DeathMagicMaxDist = Wave2.Size.X
DeathMagicDamage = DeathMagicDamage + .5
for i, plr in pairs(game.Players:GetChildren()) do
local subChar = plr.Character
if subChar ~= Character then
local EHum = subChar:FindFirstChild("Humanoid")
local Ehumrp subChar:FindFirstChild("HumanoidRootPart")
if EHum and Humrp then
local DeathMagicDistance = (Humrp.CFrame.p - Humrp.CFrame.p).Magnitude
if DeathMagicDistance <= DeathMagicMaxDist then
EHum:TakeDamage(DeathMagicDamage)
end
end
end
end
if tempCount == DeathMagicDuration then
break
end
end
end)
local goal = {}
goal.Size = Center.Size + Vector3.new(1.894,1.894,0)
local info = TweenInfo.new(.25, Enum.EasingStyle.Circular, Enum.EasingDirection.InOut)
local tween = TweenService:Create(Center,info,goal)
tween:Play()
local goal2 = {}
goal2.Size = Wave1.Size + Vector3.new(12.826,3.35,12.826)
local info2 = TweenInfo.new(.20, Enum.EasingStyle.Circular)
local tween2 = TweenService:Create(Wave1,info2,goal2)
tween2:Play()
local goal3 = {}
goal3.Size = Wave1.Size + Vector3.new(9.906,7.22,10.506)
local info3 = TweenInfo.new(.20, Enum.EasingStyle.Circular)
local tween3 = TweenService:Create(Wave2,info3,goal3)
tween3:Play()
wait(.50)
for i, object in pairs(Effects:GetChildren()) do
Like I said in the closure, in your code it appears you define Effects as local inside the if statement so it will be not transferred to the outside, you will need do
local Effects = nil
if blah == blah then
Effects = Statement
end
You should always declare a variable for FindFirstChild then check if it exists:
local Effects = workspace:FindFirstChild("Effects")
if not Effects then
Effects = Instance.new("Folder")
Effects.Name = "Effects"
Effects.Parent = workspace
end
-- code...
Here is the code down to the line that it errors
Code:
local Effects = workspace:FindFirstChild(player.Name.." Effects")
if not Effects then
local Effects = Instance.new("Folder", workspace)
Effects.Name = player.Name.." Effects"
--Debris:AddItem(Effects,DeathMagicDuration)
end
local Center = DeathMagicMeshes:WaitForChild("Center"):Clone()
Center.CFrame = Humrp.CFrame * CFrame.new(0,11.5,-20)
Center.Orientation = Center.Orientation + Vector3.new(90,0,0)
Center.Size = Vector3.new(.75,.75,29)
Center.Parent = Effects
local Wave1 = DeathMagicMeshes:WaitForChild("Wave1"):Clone()
Wave1.CFrame = Center.CFrame * CFrame.new(0,0,13.2)
Wave1.Orientation = Wave1.Orientation - Vector3.new(90,0,0)
Wave1.Size = Vector3.new(1,.1,1)
Wave1.Parent = Effects
local Wave2 = DeathMagicMeshes:WaitForChild("Wave2"):Clone()
Wave2.CFrame = Center.CFrame * CFrame.new(0,0,11)
Wave2.Orientation = Wave2.Orientation - Vector3.new(90,0,0)
Wave2.Size = Vector3.new(1,.1,1)
Wave2.Parent = Effects
spawn(function()
local tempCount = 0
while wait(1) do
tempCount = tempCount + 1
DeathMagicMaxDist = Wave2.Size.X
DeathMagicDamage = DeathMagicDamage + .5
for i, plr in pairs(game.Players:GetChildren()) do
local subChar = plr.Character
if subChar ~= Character then
local EHum = subChar:FindFirstChild("Humanoid")
local Ehumrp subChar:FindFirstChild("HumanoidRootPart")
if EHum and Humrp then
local DeathMagicDistance = (Humrp.CFrame.p - Humrp.CFrame.p).Magnitude
if DeathMagicDistance <= DeathMagicMaxDist then
EHum:TakeDamage(DeathMagicDamage)
end
end
end
end
if tempCount == DeathMagicDuration then
break
end
end
end)
local goal = {}
goal.Size = Center.Size + Vector3.new(1.894,1.894,0)
local info = TweenInfo.new(.25, Enum.EasingStyle.Circular, Enum.EasingDirection.InOut)
local tween = TweenService:Create(Center,info,goal)
tween:Play()
local goal2 = {}
goal2.Size = Wave1.Size + Vector3.new(12.826,3.35,12.826)
local info2 = TweenInfo.new(.20, Enum.EasingStyle.Circular)
local tween2 = TweenService:Create(Wave1,info2,goal2)
tween2:Play()
local goal3 = {}
goal3.Size = Wave1.Size + Vector3.new(9.906,7.22,10.506)
local info3 = TweenInfo.new(.20, Enum.EasingStyle.Circular)
local tween3 = TweenService:Create(Wave2,info3,goal3)
tween3:Play()
wait(.50)
for i, object in pairs(Effects:GetChildren()) do
if Effects then
warn("Effects folder found")
for _, Object in ipairs(Effects:GetChildren()) do
-- code
end
else
warn("Something is wrong with 'Effects' folder")
end