Help with logic behind a third person gun/tool script using raycasting

perhaps it’s better than having player calculate next player’s movement

The whole reason behind me wanting to use a ray is making sure the data is correct. I could just use mouse.Target and that would be it. If I was going for a clientside solution I wouldn’t even need a ray.

Well I got no idea about this but everything is not perfect, you lose one and get one or never got one. In term of gameplay for regular player, I would rather having raycast on ClientSide. I can think of one idea which is crazily took alot of performance so I cutted it out and try not to talk about

Perhaps I could validate the shots on the server by checking if the player you shot at is in range and other methods to make sure you aren’t exploiting it. But that is still prone to latency and would mean I should just leave it completely unprotected?

Well yeah, you can try check the range, it should atleast help abit, Unless it’s a really short range tool, otherwise you gotta expand the range abit so clientSide’s shot won’t be unvaild because of player’s movement is out of range in server side

1 Like

i wouldn’t necessarily use Mouse.Target for a gun, because what if you wanted to set a range to your gun using Mouse.Target will most likely make it harder to do so.


For stuff about exploits i would also check out these threads if you haven’t already:

2 Likes

Actually, I got another idea and that’s raycast from client and if it hit target then when a server recieve, It will recieve a TargetHumanoid,targetposition,playerposition,Damage and then you create 2 parts between targetpos and playerpos and somehow make them got ignored in gun’s raycast, make the current raycast Ignore Every Humanoid (If you have collectionService or Humanoid Checker Table) and then raycast them in the server, If hit it that part or straight up hitting target’s part then it will register the damage, this is my typical solution I can think of instead of that idea

So basically you are trying to say I would cast a ray on the client, if it hit a humanoid, send that to the server and then shoot a ray from the player’s position to the position of the humanoid they hit on the client and make sure that’s correct?

You’re right, sticking to a ray will be much better! Thank you for those threads they are really helpful at giving me ideas!

Yeah, You basically raycast from Client and then Give the Server TargetPosition and PlayerPosition Create 2 Parts out of those Target and player Pos make sure it got ignored by Gun’s Raycast, and make the current Server Raycast ignore every humanoid character and then check if it hit a part or not, If it does register the damage

u should make the Ray on Server becouse on Server all the Clients can see the bullet, if u make it on the Client only the Client can see the bullet

You could just send the info to RemoteEvent and then make a function to make a bullet on the server.

The server is the one dealing the damage and verifying the information. But the client is only doing visual stuff and figuring out what you are shooting at. So I would have to agree with them that a half-way solution is best.

Exactly, that’s what I’m going to do as well.

that will be much harder to Handle if u not make the Ray on Server

Well it’s better than having to estimate player’s movement in term of gameplay.

1 Like

How so? All I need to use is a RemoteEvent and pass the data to the server. Quite simple actually.

Have you played The Street before? You will get that feeling when you try to melee or shoot someone

if u put on Client u need more things, a remote in ReplicatedStorage so all players can see the bullet, then sending in another remote Event in ReplicatedStorage to see the Ray’s end CFrame and if the Ray hit something and the LookVector of the Ray and will be much harder becouse u will not able to see Ray’s Origin and more

To be honest, this is what most FPS programmer would do, Put Hit detection on Client so hitboxes would be better compare to server. we hate having Server hitboxes don’t we?

1 Like