You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
When player touches part, their hp is set to 1
What is the issue? Include screenshots / videos if possible!
It only works once
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Tried to print every time the part is touched by the player to see if its something wrong with the function, added a cooldown/debounce. Function prints the text but doesn’t set hp to 1, debounce does nothing.
script.Parent.Touched:Connect(function(hit)
local hum = hit.Parent:FindFirstChild("Humanoid")
if hit.Parent:FindFirstChild("Humanoid") then
hum.Health = 1
print("Hp set to 1")
end
end)
From what I understand you are trying to set the player hp to 1 when he touches a part.
Here is a working script:
script.Parent.Touched:Connect(function(hit)
local hum = hit.Parent:FindFirstChildWhichIsA("Humanoid")
if hum then
hum.Health = 1
print("Set".. hit.Parent.Name.. "health to 1")
end
end)
local player = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UserInputService = game:GetService("UserInputService")
local character = player.LocalPlayer.Character
local Humanoid = character:WaitForChild('Humanoid')
local REGEN_RATE = 50/100
local REGEN_STEP = 0.1
local particula = ReplicatedStorage.RCTParticle
particula:Clone()
particula.Enabled = false
UserInputService.InputBegan:Connect(function(Input, gameProcessed)
if Input.KeyCode == Enum.KeyCode.M then
while UserInputService:IsKeyDown(Enum.KeyCode.M) do
local dt = wait(REGEN_STEP)
local dh = dt*REGEN_RATE*Humanoid.MaxHealth
print("M held")
particula:Emit(25)
--wait(particula.Lifetime.Max)
Humanoid.Health = math.min(Humanoid.Health + dh, Humanoid.MaxHealth)
wait(0.1)
end
end
end)
UserInputService.InputEnded:Connect(function(Input, gameProcessed)
if Input.KeyCode == Enum.KeyCode.M then
wait(particula.Lifetime.Max)
print("M let go")
particula.Enabled = false
particula:Clear()
end
end)
Still does not work. Maybe it has something to do with how I removed the default roblox healing script? I made a new script in starter player called health and its empty so the character doesn’t heal naturaly