Module Script:
local module = {}
function module.NightisArriving()
local interval = .025
local change = .025
while wait(interval) do
game.Lighting.ClockTime = game.Lighting.ClockTime + change
if game.Lighting:GetMinutesAfterMidnight() > 22 * 60 then
break
end
end
end
function module.WallsCanCollide(status)
for i, v in pairs(workspace.Game.InvisibleWalls:GetChildren()) do
v.CanCollide = status
end
end
function module.MakeMusicStatus(start, End, increase)
for loop = start, End, increase do
workspace.Audio.ForestTheme.Volume = loop
wait(.05)
end
end
function module.Crickets(start, End, increase)
for loop = start, End, increase do
workspace.Audio.Crickets.Volume = loop
wait(.05)
end
end
function module.SmilingKidsParent(whatIs, parent)
local SmilingKidWithRope = whatIs
SmilingKidWithRope.Parent = parent
end
function module.SmilingKidFalls()
while true do
for i = 1, 100 do
wait()
workspace.SmilingKidWithRope:SetPrimaryPartCFrame(CFrame.new(workspace.SmilingKidWithRope.PrimaryPart.Position + Vector3.new(0,-1,0)))
end
break
end
end
function module.Fire(Status, Vol, length)
workspace.Game.Campfire.Campfire.FirePart.ParticleEmitter.Enabled = Status
local TweenService = game:GetService("TweenService")
local TweenInf = TweenInfo.new(length, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0)
local goals = Vol
local ScreenBlack = TweenService:Create(workspace.Game.Campfire.Campfire.FirePart.FireCrackles, TweenInf,{Volume = goals})
ScreenBlack:Play()
end
function module.RunMusic(Volume, Status, TimePosition)
workspace.Audio["RUN!"].Volume = Volume
workspace.Audio["RUN!"].Playing = Status
workspace.Audio["RUN!"].TimePosition = TimePosition
end
function module.ScreenTransparency(Status)
game.ReplicatedStorage.RemoteEvents.MakeScreenBlack:FireAllClients(Status)
end
function module.DistanceFromKill()
local nearestEnemy = nil
local nearestRoot = math.huge
workspace.SmilingKidWithRope.SmilingKid.Parent = workspace
local root = workspace.SmilingKid.PrimaryPart
for i, v in pairs(workspace.Game.People:GetChildren()) do
local plrRoot = v.PrimaryPart
if plrRoot and plrRoot ~= root then
local mag = (plrRoot.Position - root.Position).Magnitude
if mag < 50 and mag < nearestRoot then
nearestEnemy = plrRoot
nearestRoot = mag
end
end
if nearestEnemy then
local newpos = nearestEnemy.Position
local lookvector = nearestEnemy.CFrame.lookVector
workspace.SmilingKid:SetPrimaryPartCFrame(CFrame.new(newpos - lookvector * 3, newpos + lookvector))
plrRoot = plrRoot.Parent.Humanoid
plrRoot.WalkSpeed = 0
plrRoot.JumpPower = 0
wait(3)
plrRoot.Health = 0
end
end
end
function module.Raining(status)
for i, Part in pairs(workspace.Game.Rain:GetChildren()) do
for i, Seat in pairs(Part:GetChildren()) do
Seat.Enabled = status
end
end
end
function module.GetRidOfRope()
workspace.SmilingKidWithRope.Parent = game.ServerStorage
end
function module.TelePlayers(Pos)
game.ReplicatedStorage.RemoteEvents.TelePlayers:FireAllClients(Pos)
end
function module.HumanoidStatus(sit, wspeed, jump)
game.ReplicatedStorage.RemoteEvents.Stats:FireAllClients(sit, wspeed, jump)
end
function module.Fog(FogStart, FogEnd)
game.ReplicatedStorage.RemoteEvents.Fog:FireAllClients(FogStart, FogEnd)
end
return module
Remote Events:
--Services and locals
local plr = game.Players.LocalPlayer
local char = plr.Character
local HRP = char:WaitForChild("HumanoidRootPart")
local H = char:WaitForChild("Humanoid")
local PlayerGui = plr:WaitForChild("PlayerGui")
local TweenService = game:GetService("TweenService")
local BOF = PlayerGui.UI.BlackedOutFrame
local Rem_Events = game.ReplicatedStorage.RemoteEvents
--Remote Events
Rem_Events.MakeScreenBlack.OnClientEvent:Connect(function(Status)
local TweenInf = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0)
local goals = Status
local ScreenBlack = TweenService:Create(BOF, TweenInf,{Transparency = goals})
ScreenBlack:Play()
end)
Rem_Events.TelePlayers.OnClientEvent:Connect(function(Position)
HRP.CFrame = (Position)
end)
Rem_Events.Stats.OnClientEvent:Connect(function(SitStats, wspeed, jump)
H.Sit = SitStats
H.WalkSpeed = wspeed
H.JumpPower = jump
end)
Rem_Events.Fog.OnClientEvent:Connect(function(FogStart, FogEnd)
game.Lighting.FogStart = FogStart
game.Lighting.FogEnd = FogEnd
end)
What should I change in my code to make the memory go down? Should I disconnect function? Is that all? The code works and all, just it’s not the best on memory.