I was testing with magnitude to try and create an AOE attack for a spell but it only works for characters one at at time. How would I make it work for characters/player at the same time instead of it affecting them one at a time?
local remote = script.Parent:FindFirstChild("RemoteEvent")
local TS = game:GetService("TweenService")
remote.OnServerEvent:Connect(function(player)
local character = player.Character
local RootPart = character:WaitForChild("HumanoidRootPart")
local part = Instance.new("Part",workspace)
part.Shape = "Ball"
part.Size = Vector3.new(10,10,10)
part.CanCollide = false
part.Anchored = true
part.Color = Color3.fromRGB(255, 255, 127)
part.Material = Enum.Material.Neon
part.CFrame = RootPart.CFrame
--local tween = TS:Create(part,TweenInfo(1),{Size = Vector3.new(30,30,30),Transparency = 1}) :Play()
for i,v in pairs(game.Workspace:GetChildren()) do
if v:FindFirstChild("Humanoid") and v ~= character then
local enemy = v
local EnemyHum = v:FindFirstChild("Humanoid")
local Eroot = v:FindFirstChild("HumanoidRootPart")
if (RootPart.Position - Eroot.Position).Magnitude <= 30 then
v.HumanoidRootPart.Anchored = true
local humrp = enemy.UpperTorso
local BV = Instance.new ("BodyVelocity" ,humrp)
BV.MaxForce= Vector3.new(math.huge,math.huge,math.huge)
BV.Velocity= v.UpperTorso.CFrame.LookVector* - 10
enemy.RagdollR15.Activate.Value = true
EnemyHum:TakeDamage(math.random(45,50))
BV:Destroy()
wait(10)
enemy.RagdollR15.Activate.Value = true
--Eroot.HumanoidRootPart.Anchored = false
end
end
end
game.Debris:AddItem(part,1)
end)
I believe it’s because of the wait that you have in your code, a simple way to fix it would be to encase the code that does the AOE attack inside of a task.spawn so that way it’s done on a different thread
if (RootPart.Position - Eroot.Position).Magnitude <= 30 then
task.spawn(function()
v.HumanoidRootPart.Anchored = true
local humrp = enemy.UpperTorso
local BV = Instance.new ("BodyVelocity" ,humrp)
BV.MaxForce= Vector3.new(math.huge,math.huge,math.huge)
BV.Velocity= v.UpperTorso.CFrame.LookVector* - 10
enemy.RagdollR15.Activate.Value = true
EnemyHum:TakeDamage(math.random(45,50))
BV:Destroy()
task.wait(10)
enemy.RagdollR15.Activate.Value = true
--Eroot.HumanoidRootPart.Anchored = false
end)
end
Are there any errors when it tries to damage? If not, maybe instead of just putting the code in the if statement in the task.spawn, try putting all of this
local enemy = v
local EnemyHum = v:FindFirstChild("Humanoid")
local Eroot = v:FindFirstChild("HumanoidRootPart")
if (RootPart.Position - Eroot.Position).Magnitude <= 30 then
v.HumanoidRootPart.Anchored = true
local humrp = enemy.UpperTorso
local BV = Instance.new ("BodyVelocity" ,humrp)
BV.MaxForce= Vector3.new(math.huge,math.huge,math.huge)
BV.Velocity= v.UpperTorso.CFrame.LookVector* - 10
enemy.RagdollR15.Activate.Value = true
EnemyHum:TakeDamage(math.random(45,50))
BV:Destroy()
wait(10)
enemy.RagdollR15.Activate.Value = true
--Eroot.HumanoidRootPart.Anchored = false
end
That’s odd to say the least if it only works on non players, are you certain there’s no errors that happen when it tries to hurt a player? The only thing my eyes are noting that could be a potential problem is if Characters don’t have RagdollR15 nor Activate inside them
Your code should work since both your dummies and characters have humanoids in them