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.
--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)
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.
client (player X) fires a remote event to the server saying they are blowing a bubble
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.
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
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.
--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:
client (player X) fires a remote event to the server saying they are blowing a bubble
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.
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! :
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.