I know I have to use remote events as said in the title, but I don’t know how to, I have a remote set up and it plays the audio I want, but it doesn’t show the GUI.
Here’s my code
JWRE = game.ReplicatedStorage:WaitForChild("Remotes").JWRE
function onClicked(clicked)
if game.Workspace.isJWActive.Value == false and game.Workspace.isAJActive.Value == false then
game.Workspace.GOVL.SSA.JW.Playing = true
game.Workspace.GOVL.SSA.SA.Playing = true
game.workspace.Music.CH.Playing = true
script.Parent.Parent.Parent.Parent.SS.Enabled = true
script.Parent.Parent.Parent.Parent.SS.Text.TextLabel.Text = "JW"
game.Workspace.isJWActive.Value = true
end
end
script.Parent.MouseButton1Click:connect(onClicked)
JWRE:FireServer()
In your local script you need to have a function connected to the remote event’s OnClientEvent, in that function you would do the UI stuff you wish to do. Then, when you want it to get triggered on the client, you use RemoteEvent:FireClient(player) from the server.
--Connect your function to the OnCLientEvent of the remote
function myFunction()
--Do all your local UI stuff here
end
yourRemote.OnClientEvent:Connect(myFunction)
And this is how you fire it from the server. Run the following when you want it to fire.
How exactly would I fire it on all clients? since on FireServer and FireAllClients it says it can only be ran in a server script, and when i put it in one, it says that OnClientEvent can only be run in a local script.
Use the same code that I sent, but instead of FireClinet(player), you just do FireAllClients(). The FireAllClients that is triggering it should be on the server, and the OnClientEvent that is listening for it to be fired should be on the client.
No… You can’t connect a function to FireAllClients. And you aren’t supposed to use FireServer if you are just sending from server to the client, FireServer is for sending from the client to the server. Please, just use what I sent you:
On the CLIENT:
--Connect your function to the OnCLientEvent of the remote
function myFunction()
--Do all your local UI stuff here
end
yourRemote.OnClientEvent:Connect(myFunction)
Alright, final question or two. Am I supposed to make two different scripts
a server script with yourRemote:FireAllClients() in it?
and
--Connect your function to the OnCLientEvent of the remote
function myFunction()
--Do all your local UI stuff here
end
yourRemote.OnClientEvent:Connect(myFunction)``` in a local script?
And am I also supposed to actually create a GUI in a script, because I already have a GUI in the StarterGUI made.
Yes, yourRemote:FireAllClients() in a server script, you simply run this function in your server script whenever you want it to run, that could be at the end of a round, when the player joins, or whenever.
And yes, yourRemote.OnClientEvent:Connect(myFunction), this will be in your local script.
But no, you don’t need to create the GUI in your script, just refer to your existing GUI and do whatever you want to do with it. I don’t know what you’re actually doing with the GUI so can’t tell you what exactly to write.
Alright so for the other clients the GUI still doesn’t appear in a local script, but i’m 99% sure if I cram everything into the server script it would work, but for whatever reason it just doesn’t update any of the values (audio, gui, etc) I have no idea how to exactly fix it it and even if I put the gui in the local script and the other stuff in the server script, it still wouldn’t work because the values won’t update. I have no idea what I’m doing wrong, but here’s my code:
JWRE = game.ReplicatedStorage:WaitForChild("Remotes").JW
function myFunction()
local function onClicked(clicked)
if game.Workspace.isJWActive.Value == false and game.Workspace.isAJActive.Value == false then
game.Workspace.GOV.SSA.JW.Playing = true
game.Workspace.GOV.SSA.SSA.Playing = true
game.workspace.Music.THCF.Playing = true
script.Parent.Parent.Parent.Parent.SS.Enabled = true
script.Parent.Parent.Parent.Parent.SS.Text.TextLabel.Text = "JW"
game.Workspace.isJWActive.Value = true
end
end
script.Parent.MouseButton1Click:connect(onClicked)
end
JWRE:FireAllClients()
Sorry for the late reply, it was 4am and I had to go to bed.