Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How could I use FireAllClients() in this situation?

Hi!

So, I've been practicing scripting, decided to try to make a couple quirks from "My Hero Academia". And the script itself works fine. However, after repeated use, it starts lagging very quickly. From what I've heard I can fix that by using FireAllClients(), but I'm not sure how to implement it in this situation. Here's the script

-------SERVER-------

spikesone.OnServerEvent:Connect(function(plr)
	local chr = plr.Character
	local h = chr:WaitForChild("Humanoid")
	local anim = game.ServerStorage.Overhaul.Spikes
	local spike1 = game.ServerStorage.Overhaul.Spike:Clone()
	spike1.Name = "Spike1"
	local spike2 = game.ServerStorage.Overhaul.Spike:Clone()
	spike2.Name = "Spike2"
	local spike3 = game.ServerStorage.Overhaul.Spike:Clone()
	spike3.Name = "Spike3"
	local spike4 = game.ServerStorage.Overhaul.Spike:Clone()
	spike4.Name = "Spike4"
	local spike5 = game.ServerStorage.Overhaul.Spike:Clone()
	spike5.Name = "Spike5"
	local spike6 = game.ServerStorage.Overhaul.Spike:Clone()
	spike6.Name = "Spike6"
	local ss1 = -2.2
	local ss2 = -2.6
	local ss3 = -3
	local ss4 = -4
	local ss5 = 2
	local ss6 = 2
	local a = h:LoadAnimation(anim)
	a:Play()
	wait(.28)
	spike1.Parent = workspace
	spike2.Parent = workspace
	spike2.Size = spike1.Size * 2
	spike3.Parent = workspace
	spike3.Size = spike1.Size * 4
	spike4.Parent = workspace
	spike4.Size = spike1.Size * 6
	spike5.Parent = workspace
	spike6.Parent = workspace
	spike5.Size = spike1.Size * 8
	spike6.Size = spike1.Size * 10
	local sound = game.ServerStorage.Spikes:Clone()
	local isDamaged = false
	
	sound.Parent = workspace
	
	sound:Play()
	
	repeat wait() until spike1 and spike2 and spike3 and spike4 and spike5 and spike6
	
	spike1.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= plr.Name and isDamaged == false then
		
	end
	end)
	spike2.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= plr.Name and isDamaged == false then
		hit.HumanoidRootPart.Anchored = true
		hit.Humanoid:TakeDamage(plr.Values.Strength.Value * 2)
		wait(1)
		hit.HumanoidRootPart.Anchored = false
		isDamaged = true
	end
	end)
	spike3.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= plr.Name and isDamaged == false then
		hit.HumanoidRootPart.Anchored = true
		hit.Humanoid:TakeDamage(plr.Values.Strength.Value * 2)
		wait(1)
		hit.HumanoidRootPart.Anchored = false
		isDamaged = true
	end
	end)
	spike4.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= plr.Name and isDamaged == false then
		hit.HumanoidRootPart.Anchored = true
		hit.Humanoid:TakeDamage(plr.Values.Strength.Value * 2)
		wait(1)
		hit.HumanoidRootPart.Anchored = false
		isDamaged = true
	end
	end)
	spike5.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= plr.Name and isDamaged == false then
		hit.HumanoidRootPart.Anchored = true
		hit.Humanoid:TakeDamage(plr.Values.Strength.Value * 2)
		wait(1)
		hit.HumanoidRootPart.Anchored = false
		isDamaged = true
	end
	end)
	spike6.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= plr.Name and isDamaged == false then
		hit.HumanoidRootPart.Anchored = true
		hit.Humanoid:TakeDamage(plr.Values.Strength.Value * 2)
		wait(1)
		hit.HumanoidRootPart.Anchored = false
		isDamaged = true
	end
	end)
	
	local function size1()
		for i = -4.2,ss1,2 do
			spike1.CFrame = chr.HumanoidRootPart.CFrame * CFrame.new(0,i,-4) * CFrame.Angles(0,math.rad(180),0)
			wait()
		end
	end
	spawn(size1)
	wait(.05)
	local function size2()
		for i = -4.6,ss2,2 do
			spike2.CFrame = chr.HumanoidRootPart.CFrame * CFrame.new(0,i,-8) * CFrame.Angles(0,math.rad(180),0)
			wait()
		end
	end
	wait(.05)
	spawn(size2)
	local function size3()
		for i = -6,ss3,2 do
			spike3.CFrame = chr.HumanoidRootPart.CFrame * CFrame.new(0,i,-10) * CFrame.Angles(0,math.rad(180),0)
			wait()
		end
	end
	wait(.05)
	spawn(size3)
	local function size4()
		for i = -9,ss4,2 do
			spike4.CFrame = chr.HumanoidRootPart.CFrame * CFrame.new(0,i,-12) * CFrame.Angles(0,math.rad(180),0)
			wait()
		end
	end
	wait(.05)
	spawn(size4)
	local function size5()
		for i = -7,ss5,2 do
			spike5.CFrame = chr.HumanoidRootPart.CFrame * CFrame.new(0,i,-30) * CFrame.Angles(0,math.rad(180),0)
			wait()
		end
	end
	wait(.05)
	spawn(size5)
	local function size6()
		for i = -7,ss6,2 do
			spike6.CFrame = chr.HumanoidRootPart.CFrame * CFrame.new(0,i,-45) * CFrame.Angles(0,math.rad(180),0)
			wait()
		end
	end
	wait(.05)
	spawn(size6)
	
	wait(1)
	sound:Destroy()
	wait(1)
	spike1:Destroy()
	spike2:Destroy()
	spike3:Destroy()
	spike4:Destroy()
	spike5:Destroy()
	spike6:Destroy()
end)

------CLIENT--

if string.find(game.Players.LocalPlayer.Values.Quirk.Value, "Overhaul") then
	local plr = game.Players.LocalPlayer
	local chr = plr.Character
	local h = chr:WaitForChild("Humanoid")
	local start = game.StarterPlayer.StarterCharacterScripts.Overhaul.OverhaulMain.Start
	local activate = game.StarterPlayer.StarterCharacterScripts.Overhaul.OverhaulMain.Activate
	local spikesone = game.StarterPlayer.StarterCharacterScripts.Overhaul.OverhaulMain.Spikes1
	local deactivate = game.StarterPlayer.StarterCharacterScripts.Overhaul.OverhaulMain.DeActivate
	local disassemble = game.StarterPlayer.StarterCharacterScripts.Overhaul.OverhaulMain.Disassemble
	local heal = game.StarterPlayer.StarterCharacterScripts.Overhaul.OverhaulMain.Heal
	local uis = game:GetService("UserInputService")
	local toggle = false
	local de = true
	local de1 = true
	local de2 = true
	local de3 = true
	
	start:FireServer(plr)
	uis.InputBegan:Connect(function(i,isTyping)
		if isTyping then return end
		if i.KeyCode == Enum.KeyCode.Q then
			if de then
				if toggle == false then
					de = false
					toggle = true
					activate:FireServer(plr)
					wait(2)
					de = true
				elseif toggle == true then
					toggle = false
					de = false
					deactivate:FireServer(plr)
					wait(2)
					de = true
				end
			end
		end	
	end)
end)

1 answer

This discussion is preserved as it was. New answers, comments, and votes are closed.