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:
-
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
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.
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:
- 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! :
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
was that a built in function cuz i never seen any custom function begins with “:” And also how did you get a 2 parameters (i know player is always the first param) on OnServerEvent when you dont even put some parameter in the FireServer? Btw im sorry for interogating you this cuz I currently stuggling replicating my bullets of my gun to all clients side.
im almost a year scripter experienced Btw
I know I am very very late but, next time for performance issues only replicate the object to the closest players instead of the whole server. Someone far away wont be able to view it so why not clear up lag and not replicate it to them.