FireServer

Constructor:

FireServer(...)

Description

Client sends an event to the server to trigger a method on the server.

Parameter

Name Class Name Description
Tuple Passing parameter

Examples

First, add an event object in the WorkSpace. Create a client script in ClientfirstLogic. Client script. It can send an event to the server when the button-click event is triggered to execute the method of creating parts.

wait(1)
local person = Players:GetLocalPlayer() -- retrieve the player 
local uipanel = RWObject.Create("UiPanel") -- create a UiPanel
local uibtn = RWObject.Create("UiButton") -- create a text
uibtn.Parent = uipanel -- set the parent of the created text as the new UiPanel
uipanel.Parent = person. GameUI -- set the parent of the UiPanel as the GameUI
local eventobject = WorkSpace:WaitForChild("Event Object")
uibtn.OnClick:Connect(function()
  local number = 10
  eventobject:FireServer(number) -- send an event to the server to execute the method of creating parts; the parameter is 10
  script.Parent.Parent.IsVisable = false
end)

Server code. It can create parts of the number given by the parameter.

local eventobject = WorkSpace:WaitForChild("Event Object")
function ADD(playerid,number) -- the method of creating parts; the first parameter, which cannot be nil, is the received player UID by default.
 for i = 1,number do
     local p = RWObject.Create("Part")
     p.Name = "part"..i
     p.Position = Vector3.New(i+0.5,i+0.5,i+0.5)
     p.Anchored = true
     p.Parent = WorkSpace
    end
end
eventobject.ServerEventCallBack:Connect(ADD) -- execute creation after the server receives the event