#Local Music Isn't Working

56 messages · Page 1 of 1 (latest)

blazing void
#

So I have a Local Script put into StarterCharacterScripts that is supposed to play a specific song when the play touches a part and when the player touches another part the first song stops and a new one plays and the player is teleported to another level. This works but it works for the whole server. What I mean is: when Player 1 and 2 load in the first level song starts to play. But, when Player 1 does the level and touches the teleport block the first song stops and the second songs plays for both Player 1 and 2, despite Player 2 never even going on the level. Maybe something to do with Localization errors on my end? Not sure. I've placed my script for the Local Script below and my leaderstats script since it establishes something used for the local script (starred the part that is used).

Local Script

-- Flag Variables
local playingTF = false
local playingDM = false
local player = game.Players.LocalPlayer
local musicFolder = player:WaitForChild("Music")

local function musicPlayerTF(player)
    print("Called.")

    -- Player Variables
    local character = player.Parent
    local humanoid = character:FindFirstChild("Humanoid")
    local RSService = game:GetService("ReplicatedStorage")

    if humanoid then
        print("Human detection.")
        if not playingTF then
            musicFolder["Forest Music"]:Play()
            playingTF = true
            print("Function success.")
        else
            print("Music not repeated/played.")
        end
    end
end

local function musicplayerDM(player)
    print("Called.")
    
    -- Player Variables
    local character = player.Parent
    local humanoid = character:FindFirstChild("Humanoid")
    local RSService = game:GetService("ReplicatedStorage")
    
    if humanoid then
        print("Human detectoin.")
        if not playingDM then
            musicFolder["Forest Music"]:Stop()
            print("Music stop.")
            musicFolder["Death Mountain"]:Play()
            playingDM = true
        else
            print("Music not stopped.")
        end
    end
end

game.Workspace.Checkpoints.Lobby.Touched:Connect(musicPlayerTF)
game.Workspace["Titan Forest"].Teleporter["Forest Teleport"].Touched:Connect(musicplayerDM)

Leaderstats Script

local dataStore = game:GetService("DataStoreService")
local currencyStore = dataStore:GetDataStore("currencyStore")

game.Players.PlayerAdded:Connect(function(player)
    -- Creating leaderstat sections.
    local leaderboard = Instance.new("Folder", player)
    leaderboard.Name = "leaderstats"
    
    local deaths = Instance.new("IntValue", leaderboard)
    deaths.Name = "Deaths"

    local ltimeCount = Instance.new("IntValue", leaderboard)
    ltimeCount.Name = "Level Time"
    
    local timeCount = Instance.new("IntValue", leaderboard)
    timeCount.Name = "Total Time"
    
    local nonLeaderboard = Instance.new("Folder", player)
    nonLeaderboard.Name = "leaderstats_ns"
    
    local currency = Instance.new("IntValue", nonLeaderboard)
    currency.Name = "Coins"
    
    local leveltimeStart = Instance.new("BoolValue", nonLeaderboard)
    leveltimeStart.Name = "Level Time Start"
    leveltimeStart.Value = false
    
    local leveltimeController = Instance.new("BoolValue", nonLeaderboard)
    leveltimeController.Name = "Level Time Control"
    leveltimeController.Value = true
    
    local currencyGiven = Instance.new("BoolValue", nonLeaderboard)
    currencyGiven.Name = "Currency Given"
    currencyGiven.Value = false
    
    player.CharacterAdded:Connect(function(character)
        character:WaitForChild("Humanoid").Died:Connect(function()
            deaths.Value += 1
        end)
    end)
    
    while wait(1) do
        timeCount.Value += 1
    end
end)

**game.Players.PlayerAdded:Connect(function(player)
    local RSService = game:GetService("ReplicatedStorage")
    local musicFolder = RSService.Music:Clone()
    musicFolder.Parent = player
end)**
sage token
#

use a remote event

blazing void
#

Yep the music plays fine

blazing void
sage token
#

it would be better to check if the part was touched in a server script and then u would be able to js fire to both clients at once

blazing void
sage token
# blazing void How so

in a server script

local remote_event = path_to_remote_event
local Sound_ID = 123456789
part.Touched:Connect(function(hit)
if hit and hit.Parent:FindFirstChild(“HumanoidRootPart”) then 
remote_event:FireAllClients(Sound_ID)
end
end)
#

and then in the local script u js recieve the event

#

so

#
remote_event.OnServerEvent:Connect(function(Sound_ID)
local music = Instance.new(“Sound”)
music.SoundId = Sound_ID

music:Play()
end)
#

for more help^

blazing void
#

Ohhh I See gotcha I’ll try that and read up on it later tmr

#

Thanks

#

I’ll let yk if it works

sage token
#

alr yw

blazing void
# sage token alr yw

So wait from what I’ve read RemoteEvents make it so that a client side happens server wide

hoary lilyBOT
#

studio** You are now Level 2! **studio

blazing void
#

But I want the opposite where a person touching a brick only happens client side

sage token
#

client to server and server to client

blazing void
#

But doenst on server event only work in regualr scripts not local ones

sage token
#

in a server script

local remote_event = path_to_remote_event
local Sound_ID = 123456789
part.Touched:Connect(function(hit)
if hit and hit.Parent:FindFirstChild(“HumanoidRootPart”) then 
remote_event:FireAllClients(Sound_ID)
end
end)
#
remote_event.OnClientEvent:Connect(function(Sound_ID)
local music = Instance.new(“Sound”)
music.SoundId = Sound_ID

music:Play()
end)
#

thats server to client

sage token
sage token
sage token
#

but since u said u want the music to change for client and not one client then use FireAllClients()

sage token
blazing void
sage token
#

Then u would use

blazing void
#

(Player)

sage token
#

yes

#

yk how to get a player from who ever touched the part right?

blazing void
#

Yea that part is fine

#

First time using remoteevents that’s why it s a bit confusing loool

sage token
#

RemoteEvent:FireClient(player, Sound_ID)

sage token
#

depending on what ur doing ofc

blazing void
#

Ofc ofc

#

Alrighty I’ll try out this new approach

#

Thanks for the help again

sage token
#

but wait

#

Oh

#

Ye u can do that

#

but why didnt u js Use a local script the whole time if u js want to play the music for whoever touched the part

#

Nvm

#

js do the remote event approach

blazing void
#

It still overlapped

#

And connected to each other

sage token
#

oo alr js lmk how it goes

blazing void
#

Will dooo

blazing void
#

@sage token After a bit of tweaking it worked wonderfurlly thanks so much