My touched event is lagging in just a certain script, the rest works normal, when the part touches the player it makes a lot of lag, I’ve tried all the solutions, it’s not a union I’ve revised ALL the properties, what reasons may be generating this lag? AND HOW TO SOLVE ??? I look for solutions no more questions, I cannot show the script because it is for my client
My guess is that there is 0 debounce.
We can’t help you if you don’t post your code, any number of things could be causing lag like that.
so say all the things that can cause this lag
this script has debounce, already tried
The ideas I have would take several hours to explain in full, and are unlikely to be helpful as there are an infinite number of ways you might have made a mistake.
Why can’t you share your code, here? We don’t need the entire game, just the part dealing with the Touched event in that orb.
Well, if your debounce is 1 second, then I think you need to optimize the function that is running. We can’t really help you if we can’t see the code.
ok
script.Parent.LightBombCriarPoderEvent.OnServerEvent:Connect(function(Player)
local ReplicatedStorage = game.ReplicatedStorage
local char = Player.Character or Player.CharacterAdded:Wait()
local Ff = Instance.new("ForceField")
Ff.Parent = char:WaitForChild("Humanoid")
Ff.Visible = false
ReplicatedStorage.Nome.Value = char.Name
local root = char:WaitForChild("HumanoidRootPart")
local Humanoid = char:WaitForChild("Humanoid")
local Debounce = false
local LightBomb = ReplicatedStorage:WaitForChild("LightBomb")
local Efeito1 = ReplicatedStorage:WaitForChild("Particula")
local Efeito2 = ReplicatedStorage:WaitForChild("Efeito2")
local LightBombClone = LightBomb:Clone()
local Efeito1Clonado = Efeito1:Clone()
local Efeito2Clonado = Efeito2:Clone()
for _, playingTracks in pairs(Humanoid:GetPlayingAnimationTracks()) do
playingTracks:Stop()
end
--[[
char.HumanoidRootPart.Anchored = true
wait(0.05)
char.HumanoidRootPart.Anchored = false
--]]
local bv = Instance.new("BodyVelocity", char.PrimaryPart)
bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
bv.Velocity = Vector3.new(0,13,0)
bv.Name = "FlightForce"
wait(3.54)
bv.Velocity = Vector3.new(0,0,0)
-- 11.44 = levantar mão
wait(7.9)
Efeito2Clonado.Position = LightBombClone.Position
LightBombClone.Parent = workspace
LightBombClone.Anchored = true
Efeito1Clonado.Efeito1.Enabled = true
Efeito2Clonado.Parent = workspace
wait()
local weld = Instance.new("WeldConstraint")
weld.Part0 = Efeito2Clonado
weld.Part1 = LightBombClone
weld.Parent = Efeito2Clonado
spawn(function()
for x = 4,45,1 do
wait(0.01)
LightBombClone.Position = char.Head.Position + Vector3.new(0,x,0)
Efeito2Clonado.Position = char.Head.Position + Vector3.new(0,x,0)
end
end)
spawn(function()
for i = 1,60,1 do
wait(0.01)
LightBombClone.Size = Vector3.new(i,i,i)
Efeito2Clonado.Size = Vector3.new(i,i,i)
end
end)
wait(8.56)
local BV = Instance.new("BodyVelocity")
BV.Name = "VelocidadeDoPoder"
BV.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
BV.Parent = Efeito2Clonado
script.Parent.MousePosition.Disabled = false
script.Parent.MouseHitEvent.OnServerEvent:Connect(function(plr, Mouse)
BV.Velocity = CFrame.new(LightBombClone.Position, Mouse).LookVector * 32
end)
LightBombClone.Anchored = false
local Debounce = false
LightBombClone.Touched:Connect(function(QuemTocou)
wait(math.huge)
if not Debounce then
if QuemTocou.Name == "Chao" then
Debounce = true
wait(1)
LightBombClone.Anchored = true
Efeito1Clonado.Parent = workspace
Efeito1Clonado.Position = LightBombClone.Position + Vector3.new(0,-20,0)
Efeito2Clonado.AnimationScript.Disabled = false
char.CameraShake.Disabled = false
wait(7)
for y = 0,1,0.1 do
wait(0.1)
LightBombClone.Transparency = y
end
char.CameraShake.Disabled = true
LightBombClone:Destroy()
Efeito1Clonado:Destroy()
Efeito2Clonado:Destroy()
end
end
end)
wait(10)
--11.48 jogou
Ff:Destroy()
script.Parent.MousePosition.Disabled = true
print("Caiu")
char.Animate.Disabled = false
bv:Destroy()
--Humanoid:LoadAnimation(script.FallPose):Play()
end)
I speak another language, so I didn’t want to show
You waiting a huge number every time the touch event fires, no matter the debounce.
I’ve done more or less 200 versions without and with debounce so there’s no way this could be the problem
this is not an exaggeration
Why are you waiting for math.huge? that could be causing the lag.
No need to get upset.
I’m looking over the script right now, making changes and commenting various thing that aren’t causing the lag you’re seeing, but that you are doing “wrong”.
I understand, it is because always when people do not answer I think they are trying to see the code to help me but they just left
The only advice or possible solution I got is that don’t change/do a lot of things in a touched function because it will probably lag.
I’m talking about people who really want to help and look at the code to find a solution, not just a random solution that came to mind and hopes to work
Erm, I think this may be the issue; you are not really actually putting a debounce.
It’s just being set to
if not debounce then
Hm, well I think this could be an issue? Not too sure.
I really don’t understand what could be causing the lag, I’ve looked over the script.