I am making a killbrick, and I want to know how to change the health.
I tried:
game.Players.LocalPlayer.Health = 0
game.Players.LocalPlayer.Humanoid.Health = 0
None work. Any Ideas?
You should learn roblox lua first
heres some starter links:
Learn Roblox
Learn Roblox | Coding and Scripts
Player (roblox.com)
Player.Character (roblox.com)
I know how to do lua, but all I ever worked on was UI, like tweening and animations etc.
I have never coded anything with the player, so what do I use to change player health?
Replication is another concept you should learn about
Workspace.FilteringEnabled (roblox.com)
anyways to change the health you need to access the humanoid inside the players character
script.Parent.Touched:Connect(function(hit)
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
if Player then
local Character = hit.Parent
local Humanoid = Character:FindFirstChild("Humanoid")
if Humanoid then
Humanoid.Health = 0
end
end
end)
Ill try this now.
PS: Thanks for linking some websites ill make sure to check them out.
There are also alternative solutions to damage a player’s health, like Humanoid:TakeDamage(100), but both ways work, just saying.
Tried it, did not work.
No errors, I walked over it and took no health
its a regular script that you put it in a part, it works fine… maybe you are using a localscript
Just to add: The difference between using Humanoid.Health vs Humanoid:TakeDamage() is that Humanoid.Health doesn’t take into account whether the player has a ForceField or not
Yes, but just saying, both methods works mostly.
Copy and paste this into any item you wish to kill a player.
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
hit.Parent.Humanoid.Health = 0
print(hit)
end
end)