#Sound not playing after player respawns
5 messages · Page 1 of 1 (latest)
** You are now Level 8! **
local player = game.Players.LocalPlayer
local sound = Instance.new("Sound", player.PlayerGui)
sound.SoundId = "rbxassetid://4903742660"
local minSoundSpeed, maxSoundSpeed, acceleration = 0.5, 2, 0.05
local originalHaze, originalDensity = 2.7, game.Lighting.Atmosphere.Density
local maxHaze, maxDensity = 10, 1
local npc1, npc2 = workspace:FindFirstChild("Enemy"), workspace:FindFirstChild("TestNPC1")
local saturationDecreaseDistance, saturationDecreaseAmount, saturationDecreaseSpeed = 20, -1000, 1000
local shakeIntensity1, shakeIntensity2 = 200, 100
local RunService = game:GetService("RunService")
local originalSaturation = game.Lighting.ColorCorrection.Saturation
local function applyViewBobbing(npc, shakeIntensity)
if npc then
local dist = player:DistanceFromCharacter(npc.HumanoidRootPart.Position)
local normalizedIntensity = shakeIntensity * (1 - dist / 20)
local cam = workspace.Camera
local clamp = math.clamp(1 + (25 - 0.1) * (1 - (dist / 20)), 0.1, 25)
cam.CFrame *= CFrame.Angles(math.random(1 - clamp, clamp) / 500, math.random(1 - clamp, clamp) / 500, math.random(1 - clamp, clamp) / 500)
game:GetService('TweenService'):Create(game.Workspace.Camera, TweenInfo.new(0.2, Enum.EasingStyle.Quint, Enum.EasingDirection.Out, 0, false, 0), { CFrame = cam.CFrame * CFrame.Angles(0, 0, math.rad(math.random(-clamp / 2, clamp / 2))) }):Play()
player.Character.Humanoid.CameraOffset = Vector3.new(math.random(1 - clamp, clamp / 20), math.random(1 - clamp, clamp / 20), math.random(0 - clamp, clamp / 15)) / 55 * (normalizedIntensity / 25)
end
end
local function update()
local lighting = game.Lighting
applyViewBobbing(npc1, shakeIntensity1)
applyViewBobbing(npc2, shakeIntensity2)
local function closestNPCDistance(npc)
return npc and player:DistanceFromCharacter(npc.HumanoidRootPart.Position) or math.huge
end
local closestDist = math.min(closestNPCDistance(npc1), closestNPCDistance(npc2))
local closestNPC = (closestDist == closestNPCDistance(npc1)) and npc1 or npc2
if closestNPC and closestDist <= 20 then
local gradualVolume = 1 - (closestDist / 20)
local soundSpeed = minSoundSpeed + (maxSoundSpeed - minSoundSpeed) * (1 - closestDist / 20)
sound.PlaybackSpeed, sound.Volume = soundSpeed, math.clamp(gradualVolume * 30, 0, 100)
lighting.Atmosphere.Haze, lighting.Atmosphere.Density = originalHaze + (maxHaze - originalHaze) * gradualVolume, originalDensity + (maxDensity - originalDensity) * gradualVolume
if closestDist <= saturationDecreaseDistance then
local saturationFactor = 1 - (closestDist / saturationDecreaseDistance)
lighting.ColorCorrection.Saturation = math.clamp(originalSaturation + saturationDecreaseAmount * saturationFactor, -10000, originalSaturation)
end
if not sound.IsPlaying then
sound:Play()
end
else
if sound.IsPlaying then
sound:Stop()
end
lighting.Atmosphere.Haze, lighting.Atmosphere.Density, lighting.ColorCorrection.Saturation = originalHaze, originalDensity, originalSaturation
end
local humanoid = player.Character:FindFirstChildOfClass("Humanoid")
if humanoid and humanoid.Health <= 0 then
lighting.ColorCorrection.Saturation, lighting.Atmosphere.Haze, lighting.Atmosphere.Density = originalSaturation, originalHaze, originalDensity
end
end
RunService.RenderStepped:Connect(update)
i don't understand so much the code, but i think if you connect that to a CharacterAdded would work, i don't think so but if u can.