Hello, i made a tower game and i want to know, how to i make the music change when a block is touched
[ANNIVERSARY] Tower of Hell - Easy - Roblox this game is a example, when the player get to another floor the music changes
Really? No one knows how to make one???
I wouldn’t use .Touched
Signals as they tend to be unreliable.
Consider the following:
Wait, what, @HugeCoolboy2007 just put the links to what a sound means and @Cosmental said something about region3, can you guys explain that?
Basically, sounds are Instances that you use in your game to produce audio.
Region3 is a certain area that you can create in workspace for things like boss fight arenas or generally detecting if the player is within a certain radius. You use Workspace:FindPartsInRegion3 to get everything inside of it.
The Region3 developer hub page goes more in depth about it.
The Sound developer hub page also goes into more depth and explains it.
The developer hub pages produce code that you can use to test it.
For more explanation, I recommend watching YouTube tutorials from TheDevKing or AlvinBlox.
Ok, but… I just want the script, i am terrible programming, so, do you have the script?
We can’t give full system scripts on the forum without included explanation if no prior script was given which is why I linked to developer hub articles. I did give a small script but removed it.
I can give you this to get you started however:
-- example (localscript)
local partToTouch = -- The part that the player has to touch to change the music
local music = -- sound instance here
local player = game:GetService('Players').LocalPlayer -- this is the local player
local character = player.Character or player.CharacterAdded:Wait() -- this gets the player's character
local wasTouched = false -- basic debounce
local musicId = 0000 -- replace this with the sound id
partToTouch.Touched:Connect(function(hit) -- this event detect when it's touched and send the object that touched it as a parameter
if hit:IsDescendantOf(character) and not wasTouched then -- checks if whatever touched it is a descendant of the player's character and if the object was already touched
wasTouched = true -- sets the debounce to true
music:Stop() -- stops the music from playing momentarily
music.SoundId = "rbxassetid://" .. musicId -- this changes the music to the music if
music:Play() -- plays the new music
wait(3) -- wait 3 seconds (wait(n) isn't completely reliable however)
wasTouched = false -- sets the debounce to false
end
end)
You would have to modify it to play certain music as this is just an example script on how to get it working. I don’t usually use Region3 so I can’t show an example of that.
The forums are not for script begging man, if you have no initiative to learn it then developing might not be for you.
Wait, so are you saying that i should take my tower that took DAYS to make and put it into trash and NEVER develop again? Thank you for help
If you choose to interprete it that way then sure. Anyways you’re welcome.
The script is not working for me
Where did you place the local script. Or what does it look like on your side
I put it on a block, and how to i put the script, when i paste it on the reply it gets buggy
If you placed it in workspace, it won’t run as the only scripts that run in Workspace are Server Scripts and Module Scripts (depending on what called it). Paste it and put 3 backticks on it:
```
code here
```
So, where i put the script?
´´´
– example (localscript)
local partToTouch = Blocky-- The part that the player has to touch to change the music
local music = 5410083814-- sound instance here
local player = game:GetService('Players').LocalPlayer -- this is the local player
local character = player.Character or player.CharacterAdded:Wait() – this gets the player’s character
local wasTouched = false – basic debounce
local musicId = 5410083814 – replace this with the sound if
partToTouch.Touched:Connect(function(hit) – this event detect when it’s touched and send the object that touched it as a parameter
if hit:IsDescendantOf(character) and not wasTouched then – checks if whatever touched it is a descendant of the player’s character and if the object was already touched
wasTouched = true – sets the debounce to true
music:Stop() – stops the music from playign momentarily
music.SoundId = “rbxassetid://5410083814” … musicId – this changes the music to the music if
music:Play() – plays the new music
wait(3) – wait 3 seconds (wait(n) isn’t completely reliable however)
wasTouched = false – sets the debounce to false
end
end)
´´´
Why it din’t worked? It should not be like that
Place the script in some place like ReplicatedFirst
and
You would have to change this to something like:
local partToTouch = workspace:WaitForChild("Blocky")
Or the hierarchy to the “Blocky” Instance as just putting “Blocky” would lead to an error because the script won’t know what that is
Still not work, blocky is a block that i created, i was supposed to change the game music, but it is not working
Does it give you any errors or warnings?