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)
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