Replicating a part across all clients

Hi!

I’m having an issue with replicating a bubble part across all clients. I’v made a bubble function and am using a remote event called BlowEvent to send the bubble to the server to replicate to all clients but it is not working. I’v tried to put print statements in the bounceRemote function to see if the event is even firing but it seems to not pick it up. I’m a little stuck now and don’t really understand where I’m going wrong.

(pic below)


(gif below)

--local script
local function blowBubble(pos)
    if debounce then
        debounce = false
        --initiates bubble
        local newBubble = bubble:newBubbler(pos, actualStick)
        --run animation
        newBubble:Animate(actualStick) 
    
        wait(cooldown)
        debounce = true
        -- return pos, actualStick
    end
end

actualStick.Activated:Connect(function()
    local pos = player.character:FindFirstChild("stick").Handle.Position
    BlowEvent:FireServer(pos)
end)

BlowEvent.OnClientEvent:Connect(blowBubble)
--server script
local function bounceRemote(player, position)
    for i,v in ipairs(game.Players:GetPlayers()) do
        if v == player then
            print(position)

            replicatedStorage.Remotes.Blow:FireClient(player, position)

        end
    end
end

BlowEvent.OnServerEvent:Connect(bounceRemote)

thank you :slight_smile:

1 Like

Why don’t you just create the bubble on the server?
Why would you want to send a remote to every player just to create a part?

I recommend you just make a part when the remote has been fired in the server script

2 Likes

pro tip: don’t make anything on the server

Why not, the server is much better than handling it in the client? Also you only fire the client who fired the server.

If too many bubbles end up being created, its going to lag out the server

I see, well why do you only fire the client of the player who made the bubble. You should fire every player.

Delete this line and the “end” that goes with it:

    if v == player then

I’m trying to have a function on the client that spawns a bubble, then when a player X blows the bubble, it tells the server that player X is blowing a bubble and the server tells everyone else to run that function. So it should only fire the name of player X, or else everyone will run the function

Wait so you only want the player who blew the bubble to see it?? Every player has their own client, if one player makes a bubble on the client other players won’t see it. That’s why you have to either do it on the server or fire all clients.

Nonono, like this:

  1. client (player X) fires a remote event to the server saying they are blowing a bubble

  2. The server is like “Hmmm ok let me see your file” and gets all the information on that specific clients bubble like it’s colour, mesh, size, etc.

  3. Then the server tells everyone “Yo, player X is blowing a bubble with this information” and all the other clients (player Y, Z, etc) spawn a bubble with player X’s information on player X’s position

Yeah, but currently you are only firing the single client. I’m on mob rn but I’ll try my best to write out codee


–server script
local function bounceRemote(player, position)

replicatedStorage.Remotes.Blow:FireAllClients(player, position)
end

BlowEvent.OnServerEvent:Connect(bounceRemote)

defining all existing players in pairs to Fire to each client is the same as FireAllClients()

So idk if that’s the issue

Yes it is. Yes, you loop through every client, but before firing that client you double check that v == player. Because of that line, it won’t fire anybody except the player.

In this case, you need to create bubble on the server.
When sending to all clients with RemoteEvent, bubble will not be synchronized because there is a lag for each client.

Why would use FireAllClients for this? Unless you want it to be smooth and synchronized, there is no reason to use it. Just do this on the server and it’ll replicate to everyone.

The question has already been answered by XdJackyboiiXd21, but to reassure you you can totally do it this way. Just remember that players that just joined will not see old bubbles. Assuming Your bubbles are short lived, this is not an issue, but do make permanent parts on server.

1 Like

Hey! I ended up solving the issue btw.

--local script
local function blowBubble(user) --passing the user who blew the bubble

    if debounce then
        debounce = false

        --initiates bubble
        local newBubble = bubble:newBubbler(user)

        --run animation
        newBubble:Animate(user) 
    
        wait(cooldown)
        debounce = true

    end
end

actualStick.Activated:Connect(function()
    BlowEvent:FireServer() --player who blew the bubble displays for himself local side
    blowBubble(player) --if the player themselves blew the bubble, this runs it on the client
end)

BlowEvent.OnClientEvent:Connect(blowBubble)
--server script
-- Blow remote
local function bounceRemote(player, user)
    for i,v in ipairs(game.Players:GetPlayers()) do --getting all the players in the game

        if v ~= player then --all players BUT the one who blew it, (they already ran it on the client in the earlier code at blowBubble(player) after BlowEvent:FireServer()
            user = v
            print(user)
            BlowEvent:FireClient(v, player)

        end
    end
end

BlowEvent.OnServerEvent:Connect(bounceRemote)

What I ended up doing is instead passing the name of the client who blew the bubble to the server, then back to all the clients to say “hey, player X is blowing this bubble” and they make it appear on their own screen.

logic behind what i’m doing:

  1. client (player X) fires a remote event to the server saying they are blowing a bubble
  2. The server is like “Hmmm ok let me see your file” and gets all the information on that specific clients bubble like it’s colour, mesh, size, etc.
  3. Then the server tells everyone “Yo, player X is blowing a bubble with this information” and all the other clients (player Y, Z, etc) spawn a bubble with player X’s information on player X’s position

Personally I think this is the way to go, instead of generating everything on the server. If you try implementing it the way I did, you will notice that the latency for bubble generating goes down to zero. Also keep in mind if you are generating items on the server, it will be streaming physics data about the part and increasing its load by a lot.

If you want to test out how it looks in-game with a friend, here is the link! :

3 Likes

i dont understand, can you pls specify the difference between the user and the player, i mean who’s the doer wether the player or the user?

Hi i wonder how did you get the :newBubbler function?

Player is the person who clicked on the action, and user is everyone else. I made it a bit confusing by dong user = v when it was not really necessary.

That was just the function I wanted to replicate. You can swap it out for anything you want