So basically I have this code in my racing game, but for some reason there is a memory leak inside of my game, and I have no idea if this is the script that is causing it. But I am pretty sure it is.
This script works, but once again may have a memory leak.
Please tell me how I can make this script better and more efficient, even if you do not see a memory leak coming from this.
local done = game.Workspace.Done -- Done and racing are bool values
local racing = game.Workspace.Racing
local chosenTrack = nil
while true do
Map = nil
wait(10)
Map = game.ServerStorage.Tracks.TrackOne:Clone()
Map.Parent = game.Workspace
done.Value = false
wait(45)
game.Workspace.TrackOne.BLOCKER.SurfaceGui.SIGN.Text = "3"
wait(1)
game.Workspace.TrackOne.BLOCKER.SurfaceGui.SIGN.Text = "2"
wait(1)
game.Workspace.TrackOne.BLOCKER.SurfaceGui.SIGN.Text = "1"
wait(1)
game.Workspace.TrackOne.BLOCKER.SurfaceGui.SIGN.Text = "GO!"
game.Workspace.TrackOne.BLOCKER.SurfaceGui.SIGN.TextColor3 = Color3.fromRGB(0, 255, 0)
game.Workspace.TrackOne.BLOCKER.Transparency = 1
game.Workspace.TrackOne.BLOCKER.CanCollide = false
wait(10)
game.Workspace.TrackOne.BLOCKER.SurfaceGui.SIGN.TextTransparency = 1
if not done.Value == true then done.Changed:Wait()
wait(10)
Map:Destroy()
Map = nil
wait(10)
Map = game.ServerStorage.Tracks.TrackTwo:Clone()
Map.Parent = game.Workspace
done.Value = false
wait(45)
game.Workspace.TrackTwo.BLOCKER.SurfaceGui.SIGN.Text = "3"
wait(1)
game.Workspace.TrackTwo.BLOCKER.SurfaceGui.SIGN.Text = "2"
wait(1)
game.Workspace.TrackTwo.BLOCKER.SurfaceGui.SIGN.Text = "1"
wait(1)
game.Workspace.TrackTwo.BLOCKER.SurfaceGui.SIGN.Text = "GO!"
game.Workspace.TrackTwo.BLOCKER.SurfaceGui.SIGN.TextColor3 = Color3.fromRGB(0, 255, 0)
game.Workspace.TrackTwo.BLOCKER.Transparency = 1
game.Workspace.TrackTwo.BLOCKER.CanCollide = false
wait(10)
game.Workspace.TrackTwo.BLOCKER.SurfaceGui.SIGN.TextTransparency = 1
end
if not done.Value == true then done.Changed:Wait()
wait(10)
Map:Destroy()
Map = nil
wait(10)
Map = game.ServerStorage.Tracks.TrackThree:Clone()
Map.Parent = game.Workspace
done.Value = false
wait(45)
game.Workspace.TrackThree.BLOCKER.SurfaceGui.SIGN.Text = "3"
wait(1)
game.Workspace.TrackThree.BLOCKER.SurfaceGui.SIGN.Text = "2"
wait(1)
game.Workspace.TrackThree.BLOCKER.SurfaceGui.SIGN.Text = "1"
wait(1)
game.Workspace.TrackThree.BLOCKER.SurfaceGui.SIGN.Text = "GO!"
game.Workspace.TrackThree.BLOCKER.SurfaceGui.SIGN.TextColor3 = Color3.fromRGB(0, 255, 0)
game.Workspace.TrackThree.BLOCKER.Transparency = 1
game.Workspace.TrackThree.BLOCKER.CanCollide = false
wait(10)
game.Workspace.TrackThree.BLOCKER.SurfaceGui.SIGN.TextTransparency = 1
end
if not done.Value == true then done.Changed:Wait()
wait(10)
Map:Destroy()
Map = nil
end
end