I'm extremely new to scripting. I've been messing around and challenging myself to script certain stuff. Below is the code block, with some hopefully helpful comments.
Also, it's an edited version of the fire tutorial on the wiki.
My goal is to have my character be damaged when it touches the 'Lava1' part, taking 5 damage every second until it dies. And before my character touches the lava part, have it print "I am not on fire!"
wait(1) -- Waits for player to load in. -- Variables for the lava, users, user HP, and checking to see if player has touched lava. local Lava = game.Workspace.Lava1 local user = game.Players.LocalPlayer.Character.Humanoid local userHP = game.Players.LocalPlayer.Character.Humanoid.Health local userOnFire = Lava.Touched -- Function that creates the fire effect. function lightOnFire(part) print("Going to light this part on fire:") print(part.Name) local fire = Instance.new("Fire") fire.Parent = part end userOnFire:connect(lightOnFire) --calls upon function -- The below code begins to damage me as soon as I launch the test. -- Also, it doesn't stop even after I am dead. -- However, it does not occur during my second life (after the character has re-spawned). if userOnFire then repeat wait(1) user:TakeDamage(5) until userHP <= 0 else print("I am not on fire!") end
If this is in local script and it is in workspace it won't work because local script are different that scripts
Read More http://wiki.roblox.com/index.php?title=API:Class/LocalScript
Not only that but
game.Players.LocalPlayer.Character.Humanoid
will only work in local script
local Lava = game.Workspace.Lava1 local userOnFire = Lava.Touched -- Function that creates the fire effect. function lightOnFire(part) print("Touched name "..part.Name) --The next code checks if the part parent has child Humaniod --if it doest that fucntion will return nil local playerHumanoid = part.Parent:FindFirstChild("Humanoid") if playerHumanoid ~= nil then print("Going to light this part on fire:") local fire = Instance.new("Fire") fire.Parent = part --I remove the if because we know the part will be on fire repeat wait(1) playerHumanoid:TakeDamage(5) until playerHumanoid.Health <= 0 end end userOnFire:Connect(lightOnFire)
Forgot use Connect method.
This doesn't have debounce what that means that everytime the player touched the brick he gets the method of 5 damage every second so that builds up.