So, i tried to make a jojo game, this is my 2nd try so far the first one movements isn’t smooth so i tried changing it, but now on the 2nd Version. it lags.
as you can see, the Ping is very high. so that means it lags, right?
i tried my best to make it not lag, like making all the effects and tween in clients, making 1 Script in ServerScriptService to handle all the Damages,Projectile,Stand Movements,etc.
The 1 Script that Handles Everything:
local tab = {}
function refresh()
tab = {}
for i,v in pairs(workspace:GetDescendants()) do
table.insert(tab,v)
end
end
--[[workspace.DescendantAdded:Connect(function(child)
refresh()
end)
workspace.DescendantRemoving:Connect(function(child)
refresh()
end)
refresh()
function DEbuff(child,char)
if child.Name == "Stunned" then
local unstun = game.ServerStorage["Buffs/Debuff"].StopStunned:Clone()
unstun.Parent = char
end
end]]--
game:GetService("RunService").Heartbeat:Connect(function()
for i,v in pairs(workspace:GetDescendants()) do
--TimeStop--
--[[if v:FindFirstChild("unTS") then
v.unTS:Destroy()
if v:FindFirstChild("TS") then
v.TS:Destroy()
end
if v:IsA("Model") and v.PrimaryPart ~= nil then
v.PrimaryPart.Anchored = false
print(v.Name.." Anchored = false")
if v:FindFirstChildWhichIsA("Humanoid") then
for _,anim in pairs(v.Humanoid:GetPlayingAnimationTracks()) do
anim:AdjustSpeed(1)
end
if v:FindFirstChild("ScriptFolder") then
v.ScriptFolder:FindFirstChild(string.match(v.Name,"Input")).Disabled = false
end
end
elseif v:IsA("Part") or v:IsA("MeshPart") or v:IsA("UnionOperation") then
v.Anchored = false
print(v.Name.." Anchored = false")
end
end
if v:FindFirstChild("TS") then
if v:IsA("Model") then
v.PrimaryPart.Anchored = true
if v:FindFirstChildWhichIsA("Humanoid") then
for _,anim in pairs(v.Humanoid:GetPlayingAnimationTracks()) do
anim:AdjustSpeed(0)
end
if v:FindFirstChild("ScriptFolder") then
v.ScriptFolder:FindFirstChild(string.match(v.Name,"Input")).Disabled = true
end
end
else
v.Anchored = true
end
end]]--
--Projectiles--
if v:FindFirstChild("Projectile") then
if v.Projectile:FindFirstChild("Position") then
if not v:FindFirstChild("TS") then
local direction = CFrame.new(v.Position,v.Projectile.Position.Value)
local dist = (v.Position - v.Projectile.Position.Value).Magnitude
if dist > (v.Projectile.Value/2 + 1) then
v.Position = v.Position + (direction.LookVector * v.Projectile.Value)
else
v.Position = v.Projectile.Position.Value
end
end
elseif v.Projectile:FindFirstChild("Target") then
if not v:FindFirstChild("TS") then
local direction = CFrame.new(v.Position,v.Projectile.Target.Value.Position)
local dist = (v.Position - v.Projectile.Target.Value.Position).Magnitude
if dist > (v.Projectile.Value/2) then
v.Position = v.Position + (direction.LookVector * v.Projectile.Value)
else
v.Position = v.Projectile.Target.Value.Position
end
end
else
if not v:FindFirstChild("TS") then
local direction = v.CFrame
v.Position = v.Position + (direction.LookVector * v.Projectile.Value)
end
end
end
--CustomDebris--
if v:FindFirstChild("CustomDebris") then
if not v:FindFirstChild("TS") then
if v.CustomDebris.Value > 0 then
v.CustomDebris.Value = v.CustomDebris.Value - 0.18
else
v:Destroy()
end
end
end
--Debuffs--
if v:FindFirstChildWhichIsA("Humanoid") and not v:FindFirstChild("DebuffCheck") then
local check = Instance.new("BoolValue",v)
check.Name = "DebuffCheck"
local chcon
chcon = v.ChildRemoved:Connect(function(child)
if child.Name == "Stunned" then
local unstun = game.ServerStorage["Buffs/Debuff"].StopStunned:Clone()
unstun.Parent = v
end
end)
local dscon
dscon = v.Humanoid.Died:Connect(function()
print(v.Name.."Died")
chcon:Disconnect()
dscon:Disconnect()
end)
end
if v:FindFirstChildWhichIsA("Humanoid") and v:FindFirstChild("Stunned") then
v.Humanoid:ChangeState(Enum.HumanoidStateType.Ragdoll)
elseif v:FindFirstChildWhichIsA("Humanoid") and v:FindFirstChild("StopStunned") then
v.Humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
v.StopStunned:Destroy()
end
--Agility--
if v:FindFirstChild("Humanoid") and v:FindFirstChild("Agility") then
v.Humanoid.WalkSpeed = v.Agility.Value
end
--Damage Dealt--
if v:FindFirstChild("DamageTaken") then
if v.DamageTaken.Value > 0 and not v:FindFirstChild("TS") then
v.Humanoid:TakeDamage(v.DamageTaken.Value)
v.DamageTaken.Value = 0
end
end
--Stand Follow--
if v:FindFirstChild("aStand") then
if v:FindFirstChild("Owner") and v:FindFirstChild("FollowCFrame") then
if v.Owner.Value ~= nil then
v:SetPrimaryPartCFrame(v.PrimaryPart.CFrame:lerp(v.Owner.Value.PrimaryPart.CFrame * v.FollowCFrame.Value,((v.PrimaryPart.Position - v.Owner.Value.PrimaryPart.Position).Magnitude/1000)*v.FollowCFrame.FollowSpeed.Value))
if not workspace:FindFirstChild(v.Owner.Value.Name) or v.Owner.Value.Humanoid.Health < 0 then
v:Destroy()
end
end
end
end
end
end)
The Effects Script that Handles Tweening and Effects:
local model = Instance.new("Model",workspace)
workspace.ChildAdded:Connect(function(child)
if child.Name == "ZaWarudo" then
local ball = game.ReplicatedStorage.SpecialEffects.ZaBall:Clone()
ball.Parent = model
ball.Position = child.Value
game:GetService("TweenService"):Create(ball,TweenInfo.new(5),{Size = Vector3.new(200,200,200),Transparency = 0.7}):Play()
game.Debris:AddItem(ball,4)
wait(1)
game:GetService("TweenService"):Create(ball,TweenInfo.new(5),{Size = Vector3.new(1,1,1),Transparency = 1}):Play()
end
if child.Name == "DioKnifeHit" then
repeat wait() until not game.Lighting:FindFirstChild("TSOTP")
for i = 1,5 do
local ball = game.ReplicatedStorage.Oval:Clone()
ball.Position = child.Value
ball.Parent = model
ball.Material = "Neon"
ball.BrickColor = BrickColor.new("Really red")
local rng = math.random(4,9)
ball.Orientation = Vector3.new(math.random(-360,360),math.random(-360,360),math.random(-360,360))
game:GetService("TweenService"):Create(ball,TweenInfo.new(0.8),{Size = Vector3.new(8.92, 0.75, 0.48),Transparency = 1}):Play()
game.Debris:AddItem(ball,1)
end
end
if child.Name == "StrongPunch" then
repeat wait() until not game.Lighting:FindFirstChild("TSOTP")
for i = 1,5 do
local ball = game.ReplicatedStorage.Oval:Clone()
ball.Position = child.Value
ball.Parent = model
local rng = math.random(4,9)
ball.Orientation = Vector3.new(math.random(-360,360),math.random(-360,360),math.random(-360,360))
game:GetService("TweenService"):Create(ball,TweenInfo.new(0.8),{Size = Vector3.new(13,13,5),Transparency = 1}):Play()
game.Debris:AddItem(ball,1)
end
end
if child.Name == "NormalPunch" then
repeat wait() until not game.Lighting:FindFirstChild("TSOTP")
local ball = game.ReplicatedStorage.Oval:Clone()
ball.Position = child.Value
ball.Parent = model
local rng = math.random(4,9)
ball.Orientation = Vector3.new(math.random(-360,360),math.random(-360,360),math.random(-360,360))
game:GetService("TweenService"):Create(ball,TweenInfo.new(0.8),{Size = Vector3.new(10,1,10),Transparency = 1}):Play()
game.Debris:AddItem(ball,1)
end
if child.Name == "AoDSteal" then
wait()
local AoDSTarget = child.Value
local AoDSOwner = child.Owner.Value
for i = 1,5 do
local ball = game.ReplicatedStorage.AoDLifeStealBall:Clone()
ball.Position = AoDSTarget.PrimaryPart.Position
ball.Parent = model
game.Debris:AddItem(ball,3)
spawn(function()
game:GetService("TweenService"):Create(ball,TweenInfo.new(1),{Position = ball.Position + Vector3.new(math.random(-10,10),math.random(-10,10),math.random(-10,10)),Size = ball.Size + Vector3.new(math.random(0.5,1.5),math.random(0.5,1.5),math.random(0.5,1.5))}):Play()
wait(1)
game:GetService("TweenService"):Create(ball,TweenInfo.new(1),{Position = AoDSOwner.PrimaryPart.Position,Transparency = 1}):Play()
end)
end
end
end)
(i tried using tables for the heartbeat script, but everytime i insert a descendants into the table the game Freezes for a few seconds, Which is bad, so i decided to use Pairs instead)