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

In what situations would you use :Fireserver() ??

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?

1 comment

1

while it is more rarely used than :FireClient() (as it should be), fire server is used whenever a client has to request the server to do something. It basically does what FireClient does, but from the client to the server. you may call it at anytime when you need it as its just a function.

1 answer

✓ Accepted answer

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.

2 comments

0

Is that why you retrieve Replicated Storage? So that other players while see whatever the rest of the script does? Also, does :WaitForChild() mean that it will wait until it detects a player? What would happen if u excluded :WaitForChild()??

0

Parent argument to Instance.new is deprecated and causes performance issues if used incorrectly.

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