Music Changer Help

I’m trying to make a block that changed the music that you hear when you touch it. My only issue is when I touch it, nothing happens. My print script doesn’t send anything to my output.

script.Parent.Touched:Connect(function(hit)

if hit.Parent:FindFirstChild(“Humanoid”)then
workspace.Music.SoundId = (“rbxassetid://2010551278”)
print(“Hit!”)

end

end)

Also is workspace.Music.SoundId = (“rbxassetid://2010551278”) correct?

What about the touch function?

Not sure why your function isn’t working.

local debounce

script.Parent.Touched:Connect(function(hit)
    local character = hit:FindFirstAncestorOfClass("Model")
    if character then
        local humanoid = character:FindFirstChild("Humanoid")
        if not humanoid then
            return
        end

        debounce = true

        workspace.Music.SoundId = "rbxassetid://2010551278"
        print("Checkpoint")
        wait(5) -- change cooldown

        debounce = false
    end
end)
  • Confirm that your script is directly parented to the part.
  • Debounce added to avoid fast signals.

The parenthesis is not required.

You do not have a space between ("Humanoid") and then. Try adding a space there, as well as making the sound play after changing the SoundId.

Edit: I had just realized that the space won’t matter, but still play the music after changing the SoundId.

Spacing does not make a difference there, I tested it myself. The function has proven to not fire at all after touching. I’m certain that the script’s parented part is incorrectly set.

Additional checks

  • Are you in a TC?
  • If so, are you using collaborative editing?
  • Otherwise, could you provide full detail of the script’s ancestry and the target BasePart?

After thinking, is this a Script, or a LocalScript? If it is a LocalScript, then try moving it into StarterPlayerScripts, or anywhere where it will run.

Yes, it is a local script. How should I code it into StarterPlayerScripts?

Since the part is in workspace, consider naming the directory(ancestry) to the target part from StarterPlayerScripts using workspace.[YOUR PART NAME HERE].[OPTIONAL SUBSEQUENT PARTS].

Eureka! That worked! All I need to do now is make it a local script.

I will try to code that in and I’ll tell you what happens.

Edit: It’s now working! Thank you very much!

I do have one more question. How difficult would it be to make the songs fade in and out? How would I do it?

Here’s a radio reference we use in Vehicle Simulator

We’re currently redoing the radio so I thought we’d open source the current one.
vs_radio_export.rbxl (53.6 KB)

2 Likes

In terms of cross-fading, it is something I have trying to come up with a module. The theory goes along the lines of Track A plays until remaining X seconds and starting the Track B. At the same time, play tweening of Track A out and Track B in.

It’s not that hard, really.

1 Like

Wow! This really is old and I hate to bump topics however I will definitely be using this in my drifting game!

2 Likes