How should I create my magic casting system?

I want to create a magic casting system. I tried to set a server-client structure where when the caster clicks their mouse, if the cooldown for the current move is 0, it fires a remote to the server sending data such as the caster position and mouse position. Then if the server checks it and validates the request, it creates a key for that move instance, then send to all the clients the activation data sent by the caster and also the key (mainly for the casting client). All the clients other than the caster should start replicating the effects once getting these data. The caster should store the key sent from the server and use it to fire the remote when the magic attack hits a target. The server should perform some sanity checks and decide whether or not to confirm the damage.

But here’s the problem: Some magic attacks I want to do would involve mechanics like projectiles that follow the caster’s mouse cursor until it hits a players or obstacles (homing projectiles basically). From what I imagine, even if the casting client constantly sends the mouse position, due to replication delays, it could be possible that the results of what is hit for the casting client and other clients are different, which I don’t want to happen. So would you recommend a different structure to handle things, such as using the server to perform all the effects? Thank you for any help provided.

Note: I do not need complete scripts. I just want to know a procedure.

1 Like

give the client network control over the projectile, and have the client control where it goes.
No delay, all you have to do is checks on the server to make sure nothing illegal happens (such as an exploiter teleporting it behind a player).
If you put it on the server somehow then autoaim exploits would still be possible, so you aren’t really adding any new exploits here.

2 Likes

I don’t have a good answer for your question but some remarks instead of what you already have created. Important values like cooldown and positions should NOT be sent from the client to the server since it’s very easy to exploit. Instead the server should remember and check the important values like cooldown. (client probably needs a copy of the cooldown to more easily locally check before sending server requests but it should not be used by the server)

2 Likes

Thank you! So can I clarify if you’re saying that I should create the projectile on the server and give network ownership to the casting client? I’m just asking because I’m not sure if I should create parts on the server.

1 Like

Thank you! I understand that cooldowns should be checked on the server, and I was just saying that I want to do an extra cooldown check on the client first so (non-exploiting) players won’t be constantly creating the magic effects even if they are on cooldown.

2 Likes

you have to create the part on the server, if you create it on the client then it exists only on the client.
if you make it on the server then hand network ownership to the client, then it will not only exist on all clients, but any changes the client with ownership makes will be replicated to other clients, no middleman script required.

3 Likes

Sorry but one last thing. If I’m depending on the server to create the part in the first place, how would I allow the client to get an immediate response right after they cast the magic? Because I know that there would be delay when firing a remote.

2 Likes

it’d be just like with any of the other spells,
the client would press the button, remote fired, then nothing would happen.
Instead the client would have a way of detecting when it’s been handed a projectile to control (maybe via a remoteevent the server fires back at the client, telling them they have a projectile).
Unless the client has a really high ping, the delay should be very hard to notice, but if you want to obscure it completely the make a client side “charge” effect that plays when you start the move. So that something atleast happens when the button is presed.
O yeah remotefunctions exist too like the person below me said

3 Likes

Use RemoteFunctions, they can return data.

3 Likes

what is a good way to move the projectile

On the client you can move it a bit along it’s path every frame relative to how much time has passed since the last frame. (check out Runservice.RenderStepped)
For hitboxes however I’d recommend calculating all that on the server and to not use the part that the client has control over for the positioning of the hitbox, since most projectile attacks are predictable you can just know where to place the hitbox on the server and when to. The reason you’d want to do something like this is that you can’t trust the client, for all you know they might be exploiting and teleported that projectile behind some dudes back who’s 18 miles away.

like can you give an example of the movement cause do i just vector3 + to make the projectile move or tween or sumthing