Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago

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)

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 Code1400 75 — 4y
0
Could you send one Dev_Azure -5 — 4y
0
this is a very good video explaining remote events and stuff about the server and client. https://youtu.be/wCr5VXJ34T4 Code1400 75 — 4y
0
You have to use the remote event, or there are no other solutions. LinavolicaDev 570 — 4y
0
or remote function, with extra return values. LinavolicaDev 570 — 4y

1 answer

Log in to vote
0
Answered by
ScuffedAI 435 Moderation Voter
4 years ago
Edited 4 years ago

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
Ad

Answer this question