Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

RemoteEvent Wont Play Song? (Updated Script)

Asked by 1 year ago
Edited 1 year ago

im making a script that when you press a TextButton, it fires a RemoteEvent and changes the value of a string value to the value in the button, (the value being the name of the sound) then it will stop the previous song and start the new one but it wont play the sound, can someone help, thanks

Client Script

script.Parent.MouseButton1Click:Connect(function()
    print("touched")
    game.ReplicatedStorage.ChangeSong:FireServer()
    print("Fired Client")
    game.ReplicatedStorage["CurrentSong?"].Value = script.Parent.SongName.Value
    print("changestringval")
end)

Legacy Script (V2.0)

game:GetService("ReplicatedStorage").ChangeSong.OnServerEvent:Connect(function()
StopCurrentSong:Stop()--Change StopCurrentSong to the previous songs name.
    local name = game:GetService("ReplicatedStorage")["CurrentSong?"]
    print("createvariable")
    local song = script.Parent:FindFirstChild(tostring(name.Value))
    script.Parent:FindFirstChild(tostring(name.Value)):Play()
    print("play")
end)
0
you should replace "script.Parent:FindFirstChild(tostring(name.Value))" at line 5 with "song". shouldn't solve the problem, but you alr made the variable so NGC4637 602 — 1y

2 answers

Log in to vote
3
Answered by 1 year ago
Edited 1 year ago

It most likely won't play because the other song overrides the new one to play. To stop a song do

:Stop()

So maybe try this for the legacy script:

game:GetService("ReplicatedStorage").ChangeSong.OnServerEvent:Connect(function()
StopCurrentSong:Stop()--Change StopCurrentSong to the previous songs name.
    local name = game:GetService("ReplicatedStorage")["CurrentSong?"]
    print("createvariable")
    local song = script.Parent:FindFirstChild(tostring(name.Value))
    script.Parent:FindFirstChild(tostring(name.Value)):Play()
    print("play")
end)

Also if you have multiple choices to stop song maybe get the previous value and stop it That should work Hope this helps!!

0
ok but the song still doesnt play, if you could answer that, that would be great JmoneyPlayzOfficial 49 — 1y
0
you dont have to JmoneyPlayzOfficial 49 — 1y
0
Do you know what line the error is coming from?? If not try using print("TEST") to find it theking66hayday 841 — 1y
0
the actual legacy script doesnt run JmoneyPlayzOfficial 49 — 1y
0
is it broken or don't have it fully coded yet theking66hayday 841 — 1y
Ad
Log in to vote
0
Answered by
blowup999 659 Moderation Voter
1 year ago
Edited 1 year ago

Assuming you have filterenabled, you can't just change a value from the client in ReplicatedStorage and expect it to replicate to the Server - the Server can replicate to the Client, but not the other way around. Instead, pass the songName as a variable to the RemoteEvent.

Client:

    script.Parent.MouseButton1Click:Connect(function()
        print("touched")
        game.ReplicatedStorage.ChangeSong:FireServer(script.Parent.SongName.Value)
        print("Fired Client")
    end)

Server:

    game:GetService("ReplicatedStorage").ChangeSong.OnServerEvent:Connect(function(plr, songName)
        local song = script.Parent:FindFirstChild(tostring(songName))
        song:Play()
        print("play")
    end)

Answer this question