Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to change music on night?

2 answers

✓ Accepted answer

If you have a time of day script already implemented, then that's all you really need.

Insert another script into "ServerScriptService" or something like that in the explorer. Then the script would be something like this

TofD = game.Lighting.TimeOfDay -- variables
Sound1 = game.Workspace.Sound
Sound2 = game.Workspace.Sound2 -- You can change sound name in workspace, so it doesn't get cluttered

if TofD == 0 then
	Sound1:Play()
	if TofD == 5 then
		Sound1:Stop()
		Sound2:Play()
	end
end

This is just AN EXAMPLE, since I don't know how you want the code to be. I wouldn't copy the code. I hope this helps in someway as a reference to what you needed.

2 comments

0

I need to change sound in model

0

oh like Workspace.Model.Sound?

Hello, You can do this by simply adding a GetPropertyChangedSignal event to Lighting and checking the ClockTime.

game.Lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
	local Time = game.Lighting.ClockTime
	
	if Time >= 18 or Time <= 6 then
		print("It's night.")
		-- Your Code Here
	else
		print("It's day.")
		-- Your Code Here
	end
end)

Each time ClockTime is changed, we'll check if the time is greater or equal than 18 or less or equal than 6. If it is true, it's night, if not, it's day.

This discussion is preserved as it was. New answers, comments, and votes are closed.