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)
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!!
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)