so i made this boat as a teleporter, theres 2 of them with the same script inside
after you use the boat a few times, it freezes the game for some reason
i found out that its because of the sounds, however im confused because it shouldnt do that
ive tried adding delays between each sound but that didnt work, i tried making the sounds have a different soundid but that also didnt work
(not sure if this is relevant but in studio it freezes entirely, but in game i can still move my camera)
video of the game freezing:
heres the boat script;
local module = require(game:GetService("ReplicatedStorage").modules.mainModule)
local ts = game:GetService("TweenService")
local cooldown = false
local destination = script.destinationValue.Value
local root = script.Parent.root
local prompt = root.prompt
local destPrompt = destination.prompt
local boat = script.Parent
local destBoat = destination.Parent
local ogRootCFrame = script.ogRootCFrame
ogRootCFrame.Value = root.CFrame
local currentRootCFrame = script.currentRootCFrame
currentRootCFrame.Value = ogRootCFrame.Value
currentRootCFrame.Changed:Connect(function()
boat:PivotTo(currentRootCFrame.Value)
end)
prompt.Triggered:Connect(function(player)
if not cooldown then
if player and player.Character then
local hum = player.Character:FindFirstChildWhichIsA("Humanoid")
if hum and hum.RootPart then
cooldown = true
prompt.Enabled = false
destPrompt.Enabled = false
hum.autorotate.Value -= 1
local freeze = module.freezeHumanoid(hum)
local attachment = Instance.new("Attachment", hum.RootPart)
local align1 = Instance.new("AlignPosition")
align1.Mode = Enum.PositionAlignmentMode.TwoAttachment
align1.RigidityEnabled = true
align1.Responsiveness = 35
align1.Attachment0 = attachment
align1.Attachment1 = root.root
align1.Parent = hum.RootPart
local align2 = Instance.new("AlignOrientation")
align2.Mode = Enum.OrientationAlignmentMode.TwoAttachment
align2.RigidityEnabled = true
align2.Responsiveness = 35
align2.Attachment0 = attachment
align2.Attachment1 = root.root
align2.Parent = hum.RootPart
hum.RootPart.CFrame = root.CFrame*CFrame.new(0,5,0)
module.playAnimation(script.idle, 0.35, player)
module.playSound(script.getin, {}, hum.RootPart)
task.wait(1)
module.playSound(script.bubbles, {}, root)
module.playSound(script.bubbles, {}, destination)
boat.base["water ring"].ring.Enabled = false
destBoat.base["water ring"].ring.Enabled = false
local intensity = 0.05
local shakeConnection
shakeConnection = game:GetService("RunService").Heartbeat:Connect(function()
currentRootCFrame.Value = ogRootCFrame.Value * CFrame.new(math.random(-intensity*10000,intensity*10000)/10000,math.random(-intensity*10000,intensity*10000)/10000,math.random(-intensity*10000,intensity*10000)/10000)
destBoat.boatscript.currentRootCFrame.Value = destBoat.boatscript.ogRootCFrame.Value * CFrame.new(math.random(-intensity*10000,intensity*10000)/10000,math.random(-intensity*10000,intensity*10000)/10000,math.random(-intensity*10000,intensity*10000)/10000)
end)
task.wait(3)
shakeConnection:Disconnect()
shakeConnection = nil
currentRootCFrame.Value = ogRootCFrame.Value
destBoat.boatscript.currentRootCFrame.Value = destBoat.boatscript.ogRootCFrame.Value
module.playSound(script.submerge, {}, root)
module.playSound(script.submerge, {}, destination)
boat.Parent["splash"..string.gsub(boat.Name, "boat", "")].submerge:Emit(500)
boat.Parent["splash"..string.gsub(destBoat.Name, "boat", "")].submerge:Emit(500)
ts:Create(currentRootCFrame, TweenInfo.new(1.5, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out), {Value = ogRootCFrame.Value*CFrame.new(0,-17,0)}):Play()
ts:Create(destBoat.boatscript.currentRootCFrame, TweenInfo.new(1.5, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out), {Value = destBoat.boatscript.ogRootCFrame.Value*CFrame.new(0,-17,0)}):Play()
attachment:Destroy()
attachment = nil
align1:Destroy()
align1 = nil
align2:Destroy()
align2 = nil
local weld = Instance.new("Weld")
weld.Parent = script
weld.Part0 = hum.RootPart
weld.Part1 = root
task.wait(1)
weld.Part1 = destination
task.wait(0.5)
module.playSound(script.emerge, {}, root)
module.playSound(script.emerge, {}, destination)
task.wait(1)
ts:Create(currentRootCFrame, TweenInfo.new(3, Enum.EasingStyle.Elastic, Enum.EasingDirection.Out), {Value = ogRootCFrame.Value}):Play()
ts:Create(destBoat.boatscript.currentRootCFrame, TweenInfo.new(3, Enum.EasingStyle.Elastic, Enum.EasingDirection.Out), {Value = destBoat.boatscript.ogRootCFrame.Value}):Play()
task.wait(0.1)
boat.Parent["splash"..string.gsub(boat.Name, "boat", "")].emerge:Emit(500)
boat.Parent["splash"..string.gsub(destBoat.Name, "boat", "")].emerge:Emit(500)
task.wait(1.75)
boat.base["water ring"].ring.Enabled = true
destBoat.base["water ring"].ring.Enabled = true
module.StopAnimation(script.idle, 0.35, player)
hum.autorotate.Value += 1
freeze.unfreeze()
weld:Destroy()
weld = nil
task.wait(0.5)
prompt.Enabled = true
destPrompt.Enabled = true
cooldown = false
end
end
end
end)
any help will be appreciated