I’ve been trying to make a grenade-like tool but for some reason, the ones in phantom forces are super accurate and insanely smooth to throw, but whenever i try to make one there will be a slight delay and the throw isn’t super great either.
Of course not. I agree with this outline. The grenade can be made transparent and have its network owner set to nil to avoid any sort of interference or appearance on the client. The client would then report its simulated explosion point to the server, and the server would reconcile with its expectations under a given margin of error
I’m not sure the instance’s destruction is instant with a 0-second delay, as it’s highly likely that Debris:AddItem uses the same internal mechanism as task.delay or task.wait, which in the face of 0 seconds would still wait a frame. That’s negligible though
Try it yourself. I am speaking with a lot of experience here. I made a system like this before and if you try to destroy an instance using :Destroy() it gives a warning. To prevent that you use Debris.
display the grenade on the client, DO NOT SET THE MAIN GRENADE NETWORK OWNER, it may cause exploiters to teleport the grenade, just in the server script calculate the thows and landing position and send a event to the clientscript and tween the movement, server would handle actual grenade position with a invis part and client will only show grenade mesh with another part. prevents hackers and its more better
This would not allow for the grenade to interact with its environment. We continue to use physically simulated grenades so they may roll, fall, and bounce off of surfaces naturally. The second approach that @awry_y outlined, and the one I agree with, would not require any network ownership changes on the client due to the fact that all grenades will be created on the client
You should avoid performing any visual tasks on the server, these should always be handled on the client side. Additionally, there is no need to change the NetworkOwner like other people said. Here’s how you should proceed (bellow):
When the input is pressed or the tool is activated, begin with some sanity checks (cooldowns, raycasting, etc.). Then, fire a remote event and immediately play all effects on the LOCAL client (for yourself only). This includes throwing the grenade, emitting particles, and playing sounds.
Tool.Activated:Connect(function()
--Sanity Checks (Cooldown, Raycast...)
--RemoteEvent:FireServer(GrenadeHitPosition and other arguments you need)
--Play grenade effects (for yourself only)
end)
When the server receive the event, redo some sanity checks to make sure there is no exploits. Then, do damages to characters and FireAllClient.
RemoteEvent.OnServerEvent:Connect(function(Player, GrenadeHitPosition)
--Sanity Checks (Cooldown, Raycast...)
--RemoteEvent:FireAllClient(Player, GrenadeHitPosition)
--Do Damages - Setup Cooldowns
--Character may be found with Magnitude, GetPartInPart or whatever else using GrenadeHitPosition
--You can also get characters in client side, send them to the remote and do a magnitude check here in server side, just to verify any potential exploits, but don't forget to consider delay and ping (0.1s - 1s max) so if characters are a bit out of range, you could still do damages
end)
When all clients receive the event, the LOCAL client (yourself) won’t play the grenade effects, but all other players will be playing your grenade effect from their point of view.
RemoteEvent.OnClientEvent:Connect(function(OriginalPlayer, GrenadeHitPosition)
if not (OriginalPlayer == LocalPlayer) then
--Play grenade effects from the OriginalPlayer to its GrenadeHitPosition (not for yourself)
end
end)
This approach ensures that your grenade is thrown immediately, with a smooth movement and effects from your point of view as well as from the point of view of other players.
There is still a natural delay of 0.1 to 1 second between the moment you throw it and when other players see you do so, depending on their internet connection or wifi, but players are unlikely to notice this delay. Additionally, there should be no problems if you prevent and handle this on the server side.
there are alot of great solutions in this post. However, i will have my opinion, what u can do is throw the grenade on client and also on server at the same time where client will be handling the grenade visually, have the trajectory precalculated on server, so when the grenade is landed on server meaning trajectory is completed (t = 1), get the client position of grenade using a remote event. Now do a radius check for security, if radius of client grenade is in range of server trajectory calculation, explode the grenade. Now this may require some changes to physics behavior of grenade part on client, since sometimes it can bounce off to farther distances