Medkit/Health adding help

So i have a script that i want to heal the player when a tool is activated and their HP is less than 100. If the health is 100, it displays a message "You are at full health!". However, when my HP is less than 100, it doesnt add health at all. Please help!!

Server Sided Script:
local tool = script.Parent
local sound = tool.Handle.Sound
sound.Looped = false

local Players = game:GetService("Players")

tool.Activated:Connect(function()
	local player = Players:GetPlayerFromCharacter(tool.Parent)
	if not player then return end

	local playerGui = player:FindFirstChild("PlayerGui")
	if not playerGui then return end

	local humanoid = tool.Parent:FindFirstChildOfClass("Humanoid")
	if not humanoid then return end

	if humanoid.Health >= humanoid.MaxHealth then
		print(humanoid.Health)
		local msg = playerGui:FindFirstChild("MessageGui")
		if msg then
			local clonedMsg = msg:Clone()
			if clonedMsg then
				clonedMsg.Parent = playerGui
				clonedMsg.Message.Visible = true
				clonedMsg.Message.TextLabel.Text = "You are at full health!"
				wait(3)
				clonedMsg:Destroy()
			end
		end
	else
		sound:Play()
		local currentHealth = humanoid.Health
		print(currentHealth)
		local newHealth = math.min(currentHealth + 10, humanoid.MaxHealth)
		humanoid.Health = newHealth
		tool:Destroy()
	end
end)
1 Like

add some prints to figure out things like, if the else statement runs, what newHealth is equal to etc.
Ikr debugging is so fun.

Also like doesnt .Activated only work on the client? Cause last I checked thats how it works

You should make this a local script and use an event to fire to the server to heal the player.

I got ▶ 100 (x3) - Server - MainScript:18
apparently the server thinks im at 100 hp but im really not

Wait how are you damaging the player?

By falldamage and a tool which are different scripts

Ok the script that does damage, its a server script correct?

no its a local script the falldamage one

Well theres your problem! It needs to be a server script.
So basically whats happening is that you are dealing damage via the client, this means its only updating on the client, no other clients can see these changes, and the server cant either.
Any form of damage should be handled via the server, to learn more um heres a post on it:

I see. okay ill try to fix my script

1 Like

why would you need to use math.min? idk if it’s possible but i think Roblox auto scales health if it’s too much

I was debugging with AI it didnt really work out lol

1 Like