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

How do I use FireEvent in my Local Script? (Person said it's possible).

Hello, please review the answer to my question of 'Code works in a server script but doesn't work on a local script?'

https://imgur.com/a/kSCBtSZ

I am currently confused of how to do such thing as he didn't actually explain much. If there is a solution that doesn't involve a RemoteEvent please tell me.

My code:

local eggs = game.ReplicatedStorage.Eggs

local spawns = game.Workspace.EggSpawns
	
	local spawn = spawns.EoTS
	
	local eots = eggs["Egg of True Skill"]
	
	local eggClone = eots:Clone()
	local eggClone2 = eots:Clone()
	eggClone.Parent = game.Workspace.SpawnedEggs
	
	eggClone.Position = spawn.Position + Vector3.new(0,0.5,0)
	eggClone.Anchored = false

	eggClone.Touched:Connect(function(hit)
		local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
		
		if plr then
			game.ReplicatedStorage.FoundEgg:FireClient(plr,eggClone.Name)
			eggClone:destroy()
			

		
		end
	
	
	end)

5 comments

0

if you are trying to send information to the server the only way is to use remote events and funtions, its not that hard just watch a video on it

0

Could you send one

0

this is a very good video explaining remote events and stuff about the server and client. https://youtu.be/wCr5VXJ34T4

0

You have to use the remote event, or there are no other solutions.

0

or remote function, with extra return values.

1 answer

If i understand your code correctly you're trying to send information from a client to another client. Like i previously said in my answer, a Client cannot directly send information to another client. You can't in other words use FireClient in an localcsript.

You would have to instead send the client's information to a server and then let the server forward it to the other client. Client1 -> Server -> Client2

Here's an example on how the code would look like:

Client

-- We get the remote event and store it in a variable
local Relay = game.ReplicatedStorage:WaitForChild('RemoteEvent')

Relay.OnClientEvent:Connect(function(from,data)

	print(from .. ' just sent me this: ' .. tostring(data))
end)



local some_data = {
	text = 'Some random string',
}
Relay:FireServer('Client2',some_data)

Server

local Relay = game.ReplicatedStorage:WaitForChild('RemoteEvent')
local Players = game:GetService('Players')

Relay.OnServerEvent:Connect(player,sendTo,data)
	local from = player.Name
	local goal = Players:FindFirstChild(sendTo)
	if (goal == nil) then
		error('Unable to relay message to: ' .. sendTo)
	end

	Players:FireClient(goal,from,data)
end

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