I forgot how to use this Forum, so hopefully I can remember what to do here
I’ve always enjoyed creating Projectiles, specifically when handling them with the client/server side & vice versa via Replication but there was always one thing I struggled with whenever creating them
Now, say I create a Enemy (Not a Player) Projectile that I handle Hit Detection on the Client, and when it gets Touched, it deals damage on the server
-- Server Side
local ProjectileHandler = game.ReplicatedStorage:WaitForChild("RemoteEvent")
ProjectileHandler:FireAllClients()
ProjectileHandler.OnServerEvent:Connect(function(Plr)
local Char = Plr.Character
local Hum = Char:WaitForChild("Humanoid")
Hum:TakeDamage(25)
end)
-- Client Side
local ProjectileHandler = game.ReplicatedStorage:WaitForChild("RemoteEvent")
local LocalPlayer = game.Players.LocalPlayer
ProjectileHandler.OnClientEvent:Connect(function()
local Projectile = game.ReplicatedStorage.Projectile:Clone()
Projectile.Parent = workspace
local Connection
local function Touched(Hit)
local Plr = game.Players:GetPlayerFromCharacter(Hit.Parent)
if Plr and Plr == LocalPlayer then
Connection:Disconnect()
Projectile:Destroy()
ProjectileHandler:FireServer()
end
end
Connection = Projectile.Touched:Connect(Touched)
end)
This is a pretty straight-forward script that detects when a Projectile is hit by the LocalPlayer, and deals Damage afterwards
But say you have an Objective, or rather an NPC that’s also the same thing but isn’t a valid Player object and the Projectile is now moving at a certain distance via Physics
Now, a couple options from what I could do is check for the Hit.Parent.Name
of it, or check for a Value Object/Attribute inside it, but there’s one main thing that’s an issue: That NPC/Objective will take damage based on how much total players there are when FireAllClients()
is called
Cause as I’m trying to replicate how the Projectile & its effects whenever it gets touched, if it so happens to hit that NPC, it’ll fire “X” amount of times & deal “Y” total damage based on how much players there are overall
I’m sure for all that I know it could just be a simple solution, but I’ve struggled with trying to find the best outcome for it here, and if anyone has an idea feel free to share it out (I’m not worried about the exploits nor security, but rather I just want to get a general/good idea on how I want to accomplish this)
Things I’ve tried but didn’t work out well for reasons:
- Creating a Global Debounce for the NPC whenever it got damaged, and when not to take damage from
FireAllClients()
- Handling Projectiles on the Server (Yeaaaah no)