Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Remote Event script for audio only works in studio mode?

When the button is clicked, it fires a remote event called which plays a song. The script works in studio mode, but in server mode nothing happens when the button is clicked. Does anyone know why?

This script is inside the text button ~

local GUI = script.Parent.Parent
local button = GUI:WaitForChild("Caroline") 
button.MouseButton1Click:connect(function()
	GUI.Sound.SoundId = "rbxassetid://441341990"
	game.ReplicatedStorage.Song:FireServer()
end)

This script is placed in ServerScriptService

game.ReplicatedStorage.Song.OnServerEvent:connect(function(player)
game.Workspace.SongBoard.MainWall.SurfaceGui.ScrollingFrame.Sound:Play()
end)

Both scripts are server-side scripts the and place is Filtering Enabled, by the way.

Thanks

3 comments

0

From what I can see you change the sound id on the local script, this change will not replicate to the server. You then play the sound on the server.

0

Both scripts being server-side completely eliminates the purpose of FE and the use of the remote event. Not to mention, remotes must have a connection with both machines (client and server), rather than just one. I suggest you watch this video on remote events: https://www.youtube.com/watch?v=4Dc_bri9mjs

0

I changed the text button script to local but it wouldn't play in either studio or server mode

1 answer

#What the problem is I had a similar problem with my sniper rifle, it worked in studio but not on a server. So what is the problem? You're using an event that fires due to a player input. Meaning you shouldn't use a server script. But this is a surface gui so you need a server script? Think about it like this: both scripts are server scripts so they both can do the same thing. Functions are kind of like variables. When you call the function it's like you're putting the entire function code in its place:

local a = 1
print(a+1) --a is replaced by 1 and the answer becomes 2

function b()
	print(64^(1/3)) --That's finding the cube root of 64 btw, which is 4.
end

b() --that's the same as just copying the inside of the function and pasting it in
print(64^(1/3)) --Same output.

2

4

4


#What are functions for if they're just basically for replacing code? It can really help shorten your code instead of having to copy the same code over and over again and makes it easier to read your code also. Knowing this: We can take your second script and take that code and paste it into the first script.


#Final Product

local GUI = script.Parent.Parent
local button = GUI:WaitForChild("Caroline") 
button.MouseButton1Click:connect(function()
    GUI.Sound.SoundId = "rbxassetid://441341990"
    game.Workspace.SongBoard.MainWall.SurfaceGui.ScrollingFrame.Sound:Play()
end)

I reduced the number of scripts and I only replaced one line. Try it out!



Hope it helps!

This discussion is preserved as it was. New answers, comments, and votes are closed.