So I'm making this obby game with different worlds and stuff. It's pretty small, and each world only has around 400 parts. It works perfectly in roblox studio, but when I play it in roblox player, the game becomes unplayable.
I've also noticed that whenever I try something to reduce lag, it works for a few hours but then comes back. The microprofiler isn't showing anything either. Here's a list of things I've tried:
- Reduced the amount of moving parts at any given moment to less than 10
- Searched the code for any data leaks
- Cut down a lot of unions
I'm suspecting that it's a data leak from my kill scripts:
obstacle = script.Parent
Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PartKillModule = require(ReplicatedStorage:WaitForChild("PartKill"))
connection = Players.PlayerAdded:Connect(function(plaer)
player = plaer
plr = game.Workspace:WaitForChild(tostring(player))
end)
connection1 = obstacle.Touched:Connect(function(touched)
PartKillModule.Check(touched)
end)
if not plr == nil then
connection2 = plr.HumanoidRootPart.Touched:Connect(function(touched)
if tostring(touched) == "(Insert next checkpoint name here)" then
connection1:Disconnect()
connection:Disconnect()
obstacle = nil
player = nil
plr = nil
Players = nil
connection2:Disconnect()
end
end)
end
Here's the PartKillModule thing:
local PartKill = {}
PartKill.Check = function(touched)
local all = touched.Parent:GetChildren()
for i=1, #all, 1 do
if tostring(all[i]) == "Humanoid" then
all[i].Health = 0
end
end
all = nil
return
end
return PartKill
My original kill script never had anything about disconnecting the .Touched:Connect() function and didn't include a module either. I tried disconnecting the function right after it kills the player (if it's touched). It works, but that disables the script right after.
EDIT: I don't think my current script is actually disconnecting though, because it's not solving anything.
I know this post has been jumping around a lot and the question isn't clear, but I'm basically asking how to prevent a data leak but still making the killscript work at least until the player reaches the next checkpoint.
EDIT: Sorry about the confusing variable names, I didn't know any better way to do it.

4 comments
Maybe the touched event is firing multiple times. Try added a debounce. Ive never toyed with modules or any of that, but id put the db inside it
adding*--- Wouldn't it be crazy though if that simple thing is the solution
on wait lol i get what u mean.
Yanno? A debounce to prevent the event from firing excessively