-
What do you want to achieve? Keep it simple and clear!
I want to make a game where you battle people using different powers. -
What is the issue? Include screenshots / videos if possible!
I have created this script but it lags a lot. (There are no errors appearing) -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have tried searching on the dev forum for similar problems but had no luck.
If anyone could help me find out what is making this script so laggy it would be greatly appreciated.
Here’s the script:
script.Parent.OnServerEvent:Connect(function(plr,strike,Size,segements)
local val = Instance.new("Weld",plr)
val.Name = "Attacking"
local Folder = Instance.new("Folder",workspace)
Folder.Name = "Folder"
local function GetTouchingParts(part)
local connection = part.Touched:Connect(function() end)
local results = part:GetTouchingParts()
connection:Disconnect()
return results
end
local hum = plr.Character:WaitForChild('Humanoid')
local humRP = plr.Character:WaitForChild('HumanoidRootPart')
local ts = game:GetService("TweenService")
local radius = 5
local Char = plr.Character
wait()
--What happens
pcall(function()
local Balls = Instance.new("Model")
Balls.Parent = game.Workspace
Balls.Name = "Balls"
game.Debris:AddItem(Balls,10)
local humRp = Char:FindFirstChild("HumanoidRootPart")
local hum = Char:FindFirstChild("Humanoid")
if not humRp or not hum then return end
local ray = Ray.new(humRp.Position,humRp.CFrame.LookVector * 50)
for i = 1,23,1 do
local circle = Instance.new("Part",Balls) circle.BrickColor = BrickColor.new("Eggplant")
circle.Shape = Enum.PartType.Ball
circle.Transparency = 0.5
circle.Position = humRp.Position + Vector3.new(math.random(-7,7),math.random(3,6),math.random(-7,7))
circle.Anchored = true
circle.CanCollide = false
circle.Size = Vector3.new(radius,radius,radius)
circle.Material = "Neon"
circle.BottomSurface = "Smooth"
circle.TopSurface = "Smooth"
spawn(function()
ts:Create(circle,TweenInfo.new(.2,Enum.EasingStyle.Quad),{Position = circle.Position + Vector3.new(0,1,0)}):Play()
wait(1)
Play(script.Parent.Sfx.Woosh,humRp)
ts:Create(circle,TweenInfo.new(.1,Enum.EasingStyle.Quad),{Transparency = 0.3, Position = humRp.Position+ humRp.CFrame.LookVector * 50 + Vector3.new(math.random(-7,7),0,math.random(-7,7))}):Play()
wait(.1)
Play(script.Parent.Sfx.Blow,circle)
ts:Create(circle,TweenInfo.new(.2,Enum.EasingStyle.Quad),{Size = Vector3.new(radius*3,radius*3,radius*3), Transparency = 1}):Play()
local parts = GetTouchingParts(circle)
for i,v in pairs(parts)do
if v.Parent:FindFirstChild("Humanoid")then
v.Parent:FindFirstChild("Humanoid"):TakeDamage(.5)
end
end
local rayParams = RaycastParams.new()
rayParams.FilterDescendantsInstances = {circle}
rayParams.FilterType = Enum.RaycastFilterType.Blacklist
local ray = workspace:Raycast(circle.Position,circle.Position + Vector3.new(0,-7,0),rayParams)
if ray then
local part = Instance.new("Part",Folder)
part.Size = Vector3.new(1,1,1)
part.Anchored = false
part.Position = circle.Position
part.Material = ray.Material
part.BrickColor = ray.Instance.BrickColor
spawn(function()
wait(2)
ts:Create(part,TweenInfo.new(.2),{Transparency = 1}):Play()
end)
end
wait(.3)
end)
wait(.1)
end
wait(1)
local circle = Instance.new("Part",Balls) circle.BrickColor = BrickColor.new("Eggplant")
circle.Shape = Enum.PartType.Ball
circle.Transparency = 0.5
circle.Position = humRp.Position + Vector3.new(math.random(-7,7),math.random(3,6),math.random(-7,7))
circle.Anchored = true
circle.CanCollide = false
circle.Size = Vector3.new(radius*4,radius*4,radius*4)
circle.Material = "Neon"
circle.BottomSurface = "Smooth"
circle.TopSurface = "Smooth"
spawn(function()
ts:Create(circle,TweenInfo.new(.2,Enum.EasingStyle.Quad),{Position = circle.Position + Vector3.new(0,1,0)}):Play()
wait(1)
Play(script.Parent.Sfx.Woosh,humRp)
ts:Create(circle,TweenInfo.new(.1,Enum.EasingStyle.Quad),{Transparency = 0.3, Position = humRp.Position+ humRp.CFrame.LookVector * 50 + Vector3.new(math.random(-7,7),0,math.random(-7,7))}):Play()
wait(.1)
Play(script.Parent.Sfx.Blow,circle)
ts:Create(circle,TweenInfo.new(.8,Enum.EasingStyle.Quad),{Size = Vector3.new(radius*7,radius*7,radius*7), Transparency = 1}):Play()
local parts = GetTouchingParts(circle)
for i,v in pairs(parts)do
if v.Parent:FindFirstChild("Humanoid")then
v.Parent:FindFirstChild("Humanoid"):TakeDamage(1)
end
end
wait(1.6)
end)
end)
wait(3.9)
val:Destroy()
Folder:Destroy()
end)