Accessing an item from local script using a remote event line

I’ve tried to read the roblox page on remote events and :FireServer but I genuinely do not understand it.

When using blahblah:FireServer() can I put something in
blahblah:FireServer() ← these parentheses and call it on a serverscript?

for example,

local hitbox = Instance.new("Part")
local hitbox.Parent = Character
blahblah:FireServer(hitbox)
blahblah.OnServerEvent:Connect(function(player, hitbox)
hitbox.....
2 Likes

Well, first thing first: why don’t you try testing it out before you come to devforum and try and see if your idea works.

But, in your case, no, you cannot call :FireServer from a server-sided script - this function is only available to localscripts. Now, if you want a remote event to message localscripts, you use :FireClient(player) or :FireAllClients() on a server-sided script.

1 Like

You would need to use a bindable event if you want server to server communication, it has the same format as remote events but you dont need the player object so it souldnt be too hard to pick up

1 Like

but if you are using a remote event from a local to server script then this is the correct format

1 Like

I would also use :WaitForChild when indexing the remove events

1 Like

no no you aren’t understanding,

i’ve tried it and it doesn’t seem to work but i think im doing it wrong
lets say for example i wanna call “part”
when I do :FireServer on a local script can I put “part” in :FireServer() <— these parentheses and call in on the script im doing .OnServerEvent:Connect(function() <— here

Yes, if I understood what you said correctly, then yes.

Understand remotes as a bridge of communication between client side (local scripts) with server side (scripts). You can “send” a part, a number, a string, a table, a player. Etc.

If you need from a client script to tell a server script that you want to kill a player, then you send the player to the server.
Remote:FireServer(aPlayer, aPart, "a string", 5)

Then any server script that contains the listener of the event will run its function:

Remote.OnServerEvent:Connect(function(playerWhoFiredTheEven, playerTokill, aPart, aString, aNumber)
	warn(playerWhoFiredTheEven, "asked to kill:", playerTokill)
	warn(playerWhoFiredTheEven, "pointed a part:", aPart)
	warn(playerWhoFiredTheEven, "sent a string too:", aString, "and a number:", aNumber)
	
	aPart.CFrame = playerTokill.Character.WorldPivot -- change the position of the part to the player who will die
	playerTokill.Character.Humanoid:TakeDamage(100) -- kill the player
end)
2 Likes

Based on what was mentioned in the “Non-Replicated Instances” section of the Roblox Creator Documentation guide for Remote Events and Callbacks, objects that are locally created by the client are not replicated to the server.

As a result, when the LocalScript tries to send the client-sided object to the server via a RemoteEvent, the server would not be able to access the object.


Here’s the codeblock example provided on that page:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local remoteEvent = ReplicatedStorage:FindFirstChildOfClass("RemoteEvent")

-- Will be received as "nil" because the server doesn't know about this part
local clientPart = Instance.new("Part")
clientPart.Parent = workspace

remoteEvent:FireServer(clientPart)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.