So :Fireserver() is a remote event and a function, but why would you use it? And also here would it go in a script? Would you put it after your variables and regular functions?
Like radusavin366 said, FireServer()
is used to request the server to do something. You can call it anywhere in a LocalScript as long as you have a RemoteEvent to call it on.
For example, say you wanted to create a part when a player clicks a TextButton. You would think you could do this by just using the following code in a local script.
local button = script.Parent button.MouseButton1Click:Connect(function() -- mouseclick event local part = Instance.new("Part",workspace) part.Position = Vector3.new(0,0,0,) end
While this would create the part for the client that clicked the button, the part wouldn't be created for the server or the other clients. To fix this, you'd have to use a RemoteEvent.
LocalScript
local button = script.Parent local event = game:GetService("ReplicatedStorage"):WaitForChild('CreatePartEvent') button.MouseButton1Click:Connect(function() -- mouseclick event event:FireServer() -- in the parentheses you could include additional arguments such as position to specify where to create the part local part = Instance.new("Part",workspace) part.Position = Vector3.new(0,0,0,) end
ServerScript
local event = game:GetService("ReplicatedStorage"):WaitForChild('CreatePartEvent') event.OnServerEvent:Connect(function(player) -- player argument is automatically passed local part = Instance.new("Part",workspace) part.Position = Vector3.new(0,0,0) end)
Now, when the part is created it will be created for your client, and replicate to all the other clients as well. It doesn't matter where it goes in a script, before or after whatever variables as long as you have a remoteevent and something that Fires the remoteevent.