I got a huge smile on my face after finding out the source of my Server Memory leak issue, but I don’t know where to start.
local Runtime = game:GetService("RunService")
wait(2)
while Runtime.Stepped:Wait() do
for i, v in pairs(game.Workspace.Objects.Plants:GetChildren()) do
if v.Name == "Dandelion" then
local connection
connection = v.ClickPart.ClickDetector.MouseClick:Connect(function(player)
local Dandelion = game.ReplicatedStorage.Drops.Plants:FindFirstChild("Dandelion Head"):Clone()
local PlayerName = player.Name
local Plr = game.Players:FindFirstChild(PlayerName)
Dandelion.Parent = Plr.Backpack
local Replace = game.ReplicatedStorage.Replacement.Dandelion:Clone()
Replace.Position = v.Position - Vector3.new(0, 0.5, 0)
Replace.Name = "Root"
Replace.Parent = workspace
connection:Disconnect()
v:Destroy()
v = nil
end)
end
if v:FindFirstChild("ClickDetector") then
local connection
connection = v.ClickDetector.MouseClick:Connect(function()
if v.Name == "Log" then
game.ReplicatedStorage.Loot.Logs.Value = game.ReplicatedStorage.Loot.Logs.Value + 1
v:Destroy()
v = nil
elseif v.Name == "Stick" then
game.ReplicatedStorage.Loot.Sticks.Value = game.ReplicatedStorage.Loot.Sticks.Value + 1
v:Destroy()
v = nil
elseif v.Name == "Stone" then
game.ReplicatedStorage.Loot.Stones.Value = game.ReplicatedStorage.Loot.Stones.Value + 1
v:Destroy()
v = nil
elseif v.Name == "Raspberry" then
local connection2
connection2 = v.ClickDetector.MouseClick:Connect(function(player)
local Rasp = game.ReplicatedStorage.Drops.Plants:FindFirstChild("Raspberry"):Clone()
local PlayerName = player.Name
local Plr = game.Players:FindFirstChild(PlayerName)
local Rand = math.random(1,3)
if Rand == 3 then
local Char = workspace:FindFirstChild(PlayerName)
Char.Humanoid:TakeDamage(5)
local Physical = Char.Humanoid:GetAttribute("PhysicalDMG")
Char.Humanoid:SetAttribute("PhysicalDMG", Physical + 5)
end
Rasp.Parent = Plr.Backpack
connection2:Disconnect()
v:Destroy()
v = nil
connection2 = nil
end)
end
connection:Disconnect()
connection = nil
end)
end
end
end
I assume it has something to do with the I, v in pairs() and the function inside, but I’m not sure how to go about fixing that. I’m not looking for someone to edit the script for me but rather someone who can type up a quick explanation and solution to this.
Thanks!