script:
local part = script.Parent
local function HealthLose() game.Workspace.Health.HealthValue = -1 script.Parent.text = game.Workspace.Health.HealthValue end
part.Touched:Connect(HealthLose)
script:
local part = script.Parent
local function HealthLose() game.Workspace.Health.HealthValue = -1 script.Parent.text = game.Workspace.Health.HealthValue end
part.Touched:Connect(HealthLose)
Code:
-- Server Code
local part = script.Parent
local debounceTable = {}
local function HealthLose(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
if debounceTable[player.Name] == false then
debounceTable[player.Name] = true
game.Workspace[player.Name].Humanoid.Health = game.Workspace[player.Name].Humanoid.Health - 1
wait(1)
debounceTable[player.Name] = false
end
end
end
part.Touched:Connect(HealthLose)
-- Client Code
game.Players.LocalPlayer.Character.Humanoid.HealthChanged:Connect(function(newHealth)
HealthBar.Size = UDim2.new(newHealth / 100, 0, 1, 0)
end)
I'm sorry if this is confusing, but it's not possible to make it easier.
If you don't understand the code I recommend learning about debounce, functions like GetPlayers() or :GetPlayerFromCharacter(), guis, and finally server/client relationship.
I hope this helps!
This discussion is preserved as it was. New answers, comments, and votes are closed.
2 comments
Do you mean update a custom health bar you made?
yeah