How Do I fire event from a local script?

Your read the topic you know the question.

I want to fire a event when the local script tells the event to fire and I want a script to run when the event is fired. Can You EXPLAIN everything and make it simple and goo. Thank you for reading.

client

local RemoteEvent = --Put remote event here

RemoteEvent:FireServer(Parameters)

server

local RemoteEvent = --Put remote event here
RemoteEvent.OnServerEvent:Connect(function(PlayerwhoFired, Parameters)
--Code here
end)

Remote Events send messages to the server or can send messages to the client
Remote events work a lot like functions where you can fire the remote event with parameters

remoteEvent:FireServer("Hello World", 15, 20)
remoteEvent.OnServerEvent:Connect(function(PlayerName, StringValue, num1, num2)
	print(StringValue)
	print(num1 + num2)
end)

the server sees StringValue as “Hello World” because thats part of the parameters the client fired the remote event with, It would also print 35 because thats num1 + num2 where num1 is 15 and num2 is 20

Server can send remoteEvents to clients too

RemoteEvent:FireClient(game.Players.playerYouWantToFire, Parameters)
or 
RemoteEvent:FireAllClients(Parameters)

FireClient fires one client, while FireAllClients fires all of the clients.

RemoteEvent.OnClientEvent:Connect(function(parameters)
	--Code you want to run here
end)
3 Likes

Can you make this simpler what I want is like if a localplayer presses the Ui button then a script fires.

local

local Button = TextButton
local RemoteEvent = remoteevent

Button.MouseButton1Click:Connect(function()
	RemoteEvent:FireServer(Parameters)
end)

server

RemoteEvent.Event:Connect(function(Player, Parameters)
	--Code
end)
3 Likes