I actually see that my HP has decreased, but my physical strength remains the same for the other person. How should I fix it

I made a script that would damage you when you fall
The location was created in StarterCharacterScripts->localscript
But I actually see that my HP has decreased, but my physical strength remains the same for the other person. How should I fix it

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character

local Humanoid = Character.Humanoid
local HumanoidRootPart = Character.HumanoidRootPart

Humanoid.StateChanged:Connect(function(Oldstate , NewState)
	if NewState == Enum.HumanoidStateType.Landed then  --캐릭터가 바닥에 착륙했을때
		local Height = -HumanoidRootPart.Velocity.Y
		if Height >= 100 then
			local Damage = (Height / 80) ^4.5
			Humanoid:TakeDamage(Damage)
		end
		
	end
end)

You’re giving your player damage locally, so it takes substantially longer to replicate to other players sometimes, because it has to go from Player - Server - Other players - And the problem is, it’s not replicating to Server because FilteringEnabled isn’t replicating the change you made, the server never got word of the LocalScript’s Humanoid:TakeDamage(Damage) .

Is there a way to solve this problem?

local FallDamage = workspace:WaitForChild("FallDamage")
Humanoid.StateChanged:Connect(function(Oldstate , NewState)
	if NewState == Enum.HumanoidStateType.Landed then  --캐릭터가 바닥에 착륙했을때
		local Height = -HumanoidRootPart.Velocity.Y
		FallDamageFunction:InvokeServer(Humanoid,Height) -- Request the server to damage you
		end
		
	end
end)

In your LocalScript, I added FallDamage, a RemoteFunction located in workspace. It’s named FallDamage.

In ServerScriptService, I added a Script. This script handles every Invoke from the players securely.

local FallDamage = workspace:WaitForChild("FallDamage")

local function falldamageinvoke(Player,Humanoid,Height) -- server function
	local Damage = (Height / 80) ^4.5 
	if Humanoid and Humanoid.Parent and Player == game.Players:GetPlayerFromCharacter(Humanoid.Parent) and Height >= 100 then 
		-- We just ensured only the sending player can damage themselves. 
		Humanoid:TakeDamage(Damage)
	end
    task.wait(.125) -- reduce spam players
end

FallDamage.OnServerInvoke = falldamageinvoke
1 Like

You’re amazing. It works perfectly. Thank you.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.