The player spawns in this room, and when they touch the floor, if the sound is not playing, then the sound will play. When they try to escape by touching the walls, they will die, which I want to cause the sound to stop.
local model = script.Parent.Parent local sound = script.Parent local function onTouched(Part) if Part.Parent:FindFirstChild("Humanoid") and sound.IsPlaying == false then sound.TimePosition = 0 sound:Play() if sound.IsPlaying == true then Part.Parent.Humanoid.Died:connect(function() if sound.isPlaying then sound.Playing = false end end) end end end for i, v in pairs(model:GetChildren()) do if v:IsA('BasePart') then v.Touched:Connect(onTouched) end end
i explained this all in a codeshare so dont downvote me pls kthx
local Players = game:GetService("Players") local model = script.Parent.Parent local sound = script.Parent for _,v in pairs(model:GetChildren()) do if v:IsA("BasePart") then v.Touched:Connect(function(part) if part.Parent:FindFirstChild("Humanoid") and sound.IsPlaying == false then sound.TimePosition = 0 sound:Play() end end) end end Players.PlayerAdded:Connect(function(player) local char = player.Character or player.CharacterAdded:Wait() local hum = char:WaitForChild("Humanoid") hum.Died:Connect(function() sound:Stop() end) end)