I am developing a script where a player will click a brick, and the brick approaches their camera:
However, the brick should only move for the client who clicked said brick. I am new to ROBLOX’s Client-Server model and I am having trouble figuring out what the optimum setup for this effect would be (Remove Function/RemoteEvent.)
Since the action only has to happen for the client, is there a way to achieve this effect without a server script at all, and doing it purely locally?
Any feedback/advice you could give would be greatly appreciated.
(Edit for clarity: The above GIF shows my progress getting the brick to work with a server script in Studio using the workspace.Camera reference to determine its goal)
It can all be done on the client, but it is open to exploitation, because the client can just change the part’s position to them, click it, and your script will do whatever. If you don’t want this, you can use a RemoteEvent, where when a player clicks the ClickDetector and is fired on the server, you’ll fire a RemoteEvent to that client and the client will handle the event (where the brick goes to the player’s mouse)
-- Server script
local click = -- your click detector
local RE = -- your Remote Event
click.MouseClick:Connect(function(player)
RE:FireClient(player)
end)
-- Local script (parented to wherever it can run, such as StarterPlayerScripts)
local RE = -- your Remote Event
RE.OnClientEvent:Connect(function()
-- block goes towards the player's camera
end)
If you can help it, do not do this at all. This is pointless network overhead and involving the server where it doesn’t need to be. Only sensitive actions need to be position-checked on the server. If the click action is insignificant, this doesn’t mean anything.
A specific use case hasn’t been provided and just the details of the problem, so knowing what exactly OP is trying to make here is impossible. I doubt it’s anything important enough to involve the server. @SirNaCly, what’s your exact use case for this system?
The brick itself moving is rather insignificant, however I plan to put a surfaceGUI on the block that will act as a keypad. I assume, however, that I can separate the movement of the block from the actual keypad script meaning the movement itself can remain as purely a localscript?
If it’s for a keypad, yes, do this purely on the client. The only server interaction that should be present in your system is having the client send the inputted code to the server for verification and opening the actual door, provided a user is able to enter the code and open the doors for other users.
The block movement, the camera movement and everything - leave that to the client.
This brick is only moving towards the player to allow them to punch in the numbers on the keypad, so you only should send a RemoteEvent request to the server when they actually enter a code, and you need to check it. Nothing could be harmed from them positioning the brick in another location locally.
Edit: Didn’t know @colbert2677 replied already! My bad for posting about the same issue.
Edit 2: If this helped you, please mark it as solution.