Create the grenade with the same parameters on the client first
Then send the remote event to create the REAL damaging grenade. Replicate this as you will, fire all clients except the client that sent the remote event to replicate the grenade
if the REAL damaging grenade hits something do the explosion damage, fire client, destroy the fake grenade, and do the explosion visuals
-- Client sided
local Grenade = "Basic"
local function OnGrenadeActivated()
GrenadeModule:VisualThrow(Grenade, power, angle) -- only visuals, idk if u should make this OOP
GrenadeActivated:FireServer(power, angle)
end
-- Server Sided
local function OnServerEvent(plr, power, angle)
--probably make this some sort of OOP?
local Grenade = GrenadeModule.New()
grenade.Type = plr.EquippedGrenadeType -- don't send any data about the grenades type to the server.
--Acquire the type of grenade yourself with a string or something that the server has control over
grenade.Power = power
grenade.Height = angle
--You'd wanna check clamp the power and height variables to prevent exploiters
Grenade:DamageThrow() -- only damage!! although the Type property should contain the model too, for client-replication ofc
for i, v in Players:GetPlayers do
if v == plr then continue end
ReplicateGrenadeThrow:FireClient(v, grenade:GetProperties())
end
Grenade.Exploded:Connect(function(grenade) -- use a signal system like goodsignal for this
ReplicateGrenadeExplosion:FireAllClients(grenade:GetProperties())
end
end
-- client again
local function ExplodedGrenade(properties)
-- create a visual for the explosion, destroy grenade on client, track these grenades with IDS or something
end
local function ReplicatedGrenade(properties)
GrenadeModule:VisualThrow(properties.Type, properties.Power, properties.Angle)
end
Another suggestion you could do to optimize networking and improve responsiveness is to handle the visual destroying of the grenade completely on the client and to track these grenades use OOP. Maybe this would require it being OOP so you could track the grenade object without server-provided IDS, and if the client’s simulation bugs out the grenade wouldn’t explode where it should, so you’d probably still have to use a sort of ID system to destroy it if it already isn’t destroyed on the client (Incase of the simulation bugging out)