If you want it to take away half health, i suggest introducing the "MaxHealth" property which will return the player's max health (obviously) and then dividing it by 2.
For example:
function Touch(hit)
local hum = hit.Parent:FindFirstChild'Humanoid'
if hum then
hum:TakeDamage(hum.MaxHealth / 2)
end
end
script.Parent.Touched:connect(Touch)
However, this will still instantly kill the player. What you also need is something called a debounce method.
Explaining events
Events all work in a very common way. They will execute code when the event fires, without it waiting for the code to finish. This is where debounce comes in.
Debounce
Debounce is nothing more than making the script not run code until it's statement is true again. While it's statement is false (or nil), the event will not run the code in the event. This only happens if we use an if statement, while using a debounce method.
Exmaple:
local TouchEnabled = true
local Object = script.Parent
function Touch(Hit)
local hum = Hit.Parent:FindFirstChild'Humanoid'
if hum and TouchEnabled then
TouchEnabled = false
hum:TakeDamage(hum.MaxHealth/2)
wait(1)
TouchEnabled = true
end
end
Hope this helped. Let me know if you have any questions.
5 comments
Did you check the 'Health' Value of the Player's 'Humanoid' in Play-Solo mode?
nope, just change the script up
What do you mean by 'just change the script up'?
HELP ME??!!! LOL
I don't understand what you are trying to say; You're very vague on your Comments.