How can I make a client-sided projectile?

In that case you can do what I said, but check only on the local script if someone was hit. It will be lagless for the shooters perspective, but you are open for exploits. In that case, you can make the server apply damage no matter what the client sent, and make a server check only to see if the client is being too unconsistent (shooting too fast for the weapon that is being used for example) and procceed to kick the probable exploiter.

1 Like

Would something like this work? Also it’s not really for a fps game. It’s a blaster that’s like a magic spell.

Make so when you shoot the Projectile, you fireserver to fireallclients (except the player who cast the spell) to replicate a fake projectile, only for visuals.
Still on the local script, make so when the Projectile touches an enemy, it fireServer another remoteevent that will be used to apply damage and replicate the hit visual effect to other players via FireAllClients.

If you’re interested in how multiplayer FPS guns work, this video is pretty good:

Basically:

  • Where the bullet comes from (barrel or camera)
  • What is replicated to other players (damage or new bullets (aka hitscan or projectile weapons))
  • How all of these are processed (effects, anti cheat)
1 Like

But, you can’t use fire all client on a normal script? It’s a local script to normal script so shouldn’t it be fire server?

yo i usually do show a visual before firing a remote to the server so the client sees no delay then do fireallclients, on mobile so can’t explain further rn but reply if u need more help

yea, just fire the hitscan on the server and instead of sending events with position and direction information you just fire the remote event once and that would send a part, with a bodyvelocity in just the direction.

How do I use fire all clients from the local script?
AstronautGFX

You don’t seem to have a great understanding of the roblox engine or lua in general so I would advise you to learn remotes better. But I’ll give you the general idea and you can try work it out yourself as it’s the best way to learn.

So I usually have a local script where I have a Mouse.Button1Down:Connect() function where I’ll detect if a player has fired a projectile, then I like to have a module script so I can easily fire projectiles and I’ll call a function in the module script to fire a projectile on the client so they don’t experience delay. Then I fire an event to the server to preform hit detection and in the script I’ll have a FireAllClients() which will make a visual for the rest of the players.

If you didn’t understand all of that then you’re clearly not ready for this type of system and I strongly advise you to learn some more otherwise you will have an extremely hard time doing it.

This code doesn’t work btw, it just shows the basic idea.

Client:

local function Proj(origin,topos)
	--//make projectile here
end

Mouse.Button1Down:Connect(function()
	Proj(origin,topos) --//Make projectile for client 

	game.ReplicatedStorage.RemoteEvent:FireServer(origin,topos)
end)

game.ReplicatedStorage.Visuals.OnClientEvent:Connect(function(plr,origin,topos)
	if localplayer ~= plr then --//make sure were not making two projectiles for the client
		Proj(origin,topos) --//Make projectile for client 
	end
end)

Server:

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr,origin,topos)
	--//do raycasting hitdetection
	
	game.ReplicatedStorage.Visuals:FireAllClients() --//make projectile for all players
end)
8 Likes