So I have a potion in my game that causes effects everytime when drinked, all the effects/visuals are on client and the code has been optimized. The effects are particles and a parts that gets cloned in everytime the player moves (kind of as an path).
I though the lagspikes came from the script but then i tried deleting most of the map and the lag spikes got reduced so that it was almost unnoticeable but what confused me the most was that the map only has 1,7k parts and contains barely any unions. I’ve tried using “microprofiler” but i can’t understand what the labels mean.
I have looked for solutions in other devforum posts but can’t seem to find a fitting one. Becuase of the amount of parts being so low it must be some kind of script issue? I don’t know if this topic fits in this category or not but I dont know where else to post this.
Personally, when I had a pretty big and laggy script which cannot be less laggy than it is, I’ve made other scripts to try to reduce any source of lag that is not coming from the script, for example, a custom rendering system which renders blocks according to your computer FPS, or a script that shuts down all other scripts which aren’t being used at the moment and many more options.
Although, if you think that wouldn’t help, I would suggest trying to minimise the script usage, try to think of ideas to make the script do less while accomplishing the same tasks.
I have checked so that the listener gets disconnected and the the “acid” part doesn’t get cloned more times than needed.
function Chemicals.CreateAcid(player, Handle)
local char = player.Character
if listener then
listener:Disconnect()
end
listener = char.Humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
if db then
db = false
local Acid = game.ReplicatedStorage.Acid:Clone()
if char.Humanoid.FloorMaterial ~= Enum.Material.Air and char.Humanoid.MoveDirection:Dot(char.Humanoid.MoveDirection) > 0.1 then
Acid.Position = char.HumanoidRootPart.Position - Vector3.new(0, (char.Humanoid.HipHeight + 1), 0)
Acid.BrickColor = Handle.Fluid.BrickColor
Acid.Bubbles.Enabled = true
Acid.Parent = workspace
end
wait(.25)
Debris:AddItem(Acid, 1.5)
db = true
end
end)
end```
I think the problem is in the script that’s calling the function (which I am assuming is in a module script).
If I am correct and it is a module script, make sure that it is not calling another module script that calls it back (they would call each other forever).
Also, instead of moving the acid every time the player walks, try to weld the acid to the player’s HumanoidRootPart, and it will move with the player.
Well what is going on is whenver the tool is used it fires a signl to the server which fires an remote to all clients, then the clients invoke the module script that creates the acid trail, I have also checked so that they dont call each other forever.
I though of that idea but that wouldn’t create an acid trial and just a part that follow the Humanoidrootpart.
I honestly don’t know if its the script because i have looked through it a bunch of times now and all the parts shouldnt be causing the lag becuase its only 1,7k?
AHA!!! Life’s mysteries have been solved.
Each client calls the modulescript (the module script operates from the client since you called it from the client), which basically creates the listener that many times, which is creating the lag (I think lol).
Since you’re firing the module from each client, you are basically mimicking what roblox would do if you just did it from the server, but not including the server in the replication. To do the same thing but with less lag just do everything from the server, and insert a boolvalue “inHiding” marked true, which you check every time the server is looking at the object, and if the server finds the value (not necessarily has to be true), it skips.
I hope that makes sense, and I hope I have pinpointed the problem
Hey I will try you solution if this works I am gonna be so grateful as i’ve been trying to find a solution for quite some time now and honestly was just considering of rebuilding the whole map, ill send another message if it works or not thanks.
Oh thats what I tried and it reduced the lag alot I asked a couple people and it makes no sense that the map is making it lag because of the part count being only 1,7k while i looked at another topic saying that keeping the game at around 10k parts should be good.