#Learning Roblox Scripting – Struggling with Client-Server

1 messages · Page 1 of 1 (latest)

minor ember
#

Hey, I’m learning Roblox scripting and also relearning Lua from scratch. I have experience with JavaScript, C#, C++, and Python, but I never fully understood how the client-server system works (LocalScripts, ServerScripts, Remote Events, etc.). This has always been a roadblock for me.

Can someone clearly explain how client-server communication works and when to use each type of script? Also, how did you approach learning scripting when you first started? Any good resources you’d recommend?

solar remnant
#

client server cant change server sided value or anything on server.

#

so u need to use remote events to do that

#

i learn scripting my watching videos

minor ember
solar remnant
#

TheDevKing?

minor ember
#

thank you

agile sierra
#

its easy bro like client is what the players can do or the client do that the servers cant like clicking a button.

#

guis, etc.

#

but you can communicate to the server by using remote events

#

like if you click the button on the client you will tell the server to do something about it

#

also there is something like um filter enabled thingy

minor ember
#

thanks that makes sense so anything the player directly interacts with (like ui , buttons,etc.) runs on the client if i need to make changes that effect the whole game i communicate with the server using remote events got it

agile sierra
#

like if you change something on the client like changing a part on the client side the players will not see it the changing position of a part simply because it doesnt replicated on the server.

agile sierra
#

exactly

#

if you want to make the other player see the changes in your client side then you will need to communicate with servers

minor ember
#

also i can optimize the game with those right

subtle meadow
#

whats important to realize is that the server doesn't see the same world as each client does. like you can create a part on a client and only that client will see the part.

minor ember
sage vineBOT
#

studio** You are now Level 1! **studio

subtle meadow
minor ember
#

got it

#

thank you for your help

subtle meadow
#

if you do the moving parts on the client, yeah it's cheaper, but you are limited by the client's device instead of network capacity

#

like a phone aint gonna handle a massive building exploding into 10k tiny pieces

agile sierra
#

to optimize your game i can give little tip if you are using tween service then you should it on client side rather than server side 🙂

#

tween service can be use both server and client but this is not useful for uhm server because y'know it also leads memory leaking

subtle meadow
#

networking is usually the largest bottleneck

agile sierra
subtle meadow
agile sierra
#

but yeah this is just a little tip to avoid lag sometimes

subtle meadow
#

i.e if you create a part in workspace, and an objectvalue with its value set to that part, and then you delete the part, the objectvalue will still have a valid reference to the part, and the part stays in memory until the objectvalue is destroyed

#

that's a memory leak if you do something like that and never clean it up

agile sierra
#

yeah. but i have a question how do you clean up the old data that has been destroyed but its still reference in the memory?

#

like if a player joins does it mean it adds it to the memory?

subtle meadow
#

"destroying a reference" usually just means setting stuff to nil

agile sierra
subtle meadow
#

same for playertable[plr]=plr.userid

#

if you don't set those to nil, the player stays alive

agile sierra
#
game.Players.PlayerAdded:Connect(function(plr)
    plrTable[plr.UserId] = plr
end)

game.Players.PlayerRemoving:Connect(function(plr)
    plrTable[plr.UserId] = nil
end)```
#

how about the character?

#

like if they died multiple times?

subtle meadow
#

yep same thing if you keep references to old characters they stay alive

agile sierra
#

ok so i will make another table for character? and make it nil?

#

whenever the char died

#

?

subtle meadow
#

if you never store the player in a table to start with you dont have to care