Hello! I’ve been working on an FPS game recently, and I’ve been running into one big problem. When you shoot somebody, the raycasting and damage calculations are done on the server, and then sent to the client that took the damage via a remoteevent. The issue I have is that the remote event is just not firing. There is nothing in the console, but the client doesn’t even get the remoteevent.
This is the code that runs on the server when somebody gets shot
if hitpart.Parent:FindFirstChild("Humanoid") then
warn("Player "..player.Name.." hit a shot, calculating damage")
if hitpart.Name:match("Head") then
damage = game.Workspace[weapon].damage.Value * 4
warn("Player "..player.Name.." did "..damage.." damage to "..hitpart.Parent.Name)
end
if hitpart.Name:match("UpperTorso") or hitpart.Name:match("Arm") or hitpart.Name:match("Hand") then
damage = game.Workspace[weapon].damage.Value * 1
warn("Player "..player.Name.." did "..damage.." damage to "..hitpart.Parent.Name)
end
if hitpart.Name:match("LowerTorso") then
damage = game.Workspace[weapon].damage.Value * 1.2
warn("Player "..player.Name.." did "..damage.." damage to "..hitpart.Parent.Name)
end
if hitpart.Name:match("Leg") then
damage = game.Workspace[weapon].damage.Value * 0.75
warn("Player "..player.Name.." did "..damage.." damage to "..hitpart.Parent.Name)
end
game.ReplicatedStorage.damage:FireClient(game.Players[hitpart.Parent.Name], math.floor(damage), player, killerhealth, weapon)
print("sending damage to player")
else
And this is the code that runs on the client.
game.ReplicatedStorage.damage.OnClientEvent:Connect(function(damage, player, health, weapon)
game.Players.LocalPlayer.PlayerScripts.health -= damage
print("damage taken")
if game.Players.LocalPlayer.PlayerScripts.health < 1 then
print("player died")
game.Players.LocalPlayer.PlayerGui.ScreenGui.death.killed.Text = player.Name.." killed you."
game.Players.LocalPlayer.PlayerGui.ScreenGui.death.killed.Visible = true
game.Players.LocalPlayer.PlayerGui.ScreenGui.death.damage.Text = player.Name.." killed you with their "..gametoweaponname(weapon).."."
game.Players.LocalPlayer.PlayerGui.ScreenGui.death.damage.Visible = true
end
end)
I think there is an error in 2nd line of local script
btw it’s not suggested to do as you are doing…
this might be easy for exploiters to manulipate…
Instead reduce health in server script and use humanoid.dead function in the local script
Yeah, I was thinking this would be easy for exploiters, but I have to do this in a localscript because the player’s health and weapons are stored in PlayerScripts.
this code is super unoptimized btw, you shouldn’t repeat code if you have a way to avoid it
in this case, this should work
local DamageMultipliers = {
Head = 4,
LowerTorso = 1.2,
Leg = .75
}
if hitpart.Parent:FindFirstChild("Humanoid") then
warn(string.format("Player %s hit a shot, calculating damage"):format(player.Name))
local DamageMultiplier = DamageMultipliers[hitpart.Name] or 1 --if it exists in the table, then the multiplier is the one stored in the table, if it isn't, the multiplier defaults to one
damage = workspace[weapon].damage.Value * DamageMultiplier
warn(string.format("Player %s did %s damage to %s"):format(player.Name, tostring(damage), hitpart.Parent.Name))
game.ReplicatedStorage.damage:FireClient(game.Players[hitpart.Parent.Name], math.floor(damage), player, killerhealth, weapon)
print("sending damage to player")
else