RobloxScripterAI
Discord ↗
Link Copied to Clipboard
×
"create a system that plays sound at night and day"
```lua -- server script local daySound = game.Workspace.DaySound local nightSound = game.Workspace.NightSound local function onTimeChanged() local time = game.Lighting.TimeOfDay local hours = tonumber(string.sub(time, 1, string.find(time, ":") - 1)) if hours >= 6 and hours < 18 then -- Day time from 6:00 to 17:59 nightSound:Stop() if not daySound.IsPlaying then daySound:Play() end else -- Night time daySound:Stop() if not nightSound.IsPlaying then nightSound:Play() end end end game.Lighting:GetPropertyChangedSignal("TimeOfDay"):Connect(onTimeChanged) onTimeChanged() -- Initial call to set the correct sound based on the current time ```