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)
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: