This code should be more efficient and please look at the comments describing the code.
local Players = game:GetService("Players")
local lava = script.Parent
local FIRE_ONLY_ONCE = true
lava.Touched:Connect(function(hit)
local model = hit:FindFirstAncestorOfClass("Model")
if model then
local player = Players:GetPlayerFromCharacter(model)
if player then
local head = model:FindFirstChild("Head")
if head then
if FIRE_ONLY_ONCE then
if not head:FindFirstChild("Fire") then
local Fire = Instance.new("Fire", head)
Fire.Heat = 9
Fire.Name = "Fire"
Fire.Enabled = true
Fire.Size = 5
Fire.Color = Color3.fromRGB(236, 139, 70)
Fire.SecondaryColor = Color3.fromRGB(139, 80, 55)
end
else
local Fire = Instance.new("Fire", head)
Fire.Heat = 9
Fire.Name = "Fire"
Fire.Enabled = true
Fire.Size = 5
Fire.Color = Color3.fromRGB(236, 139, 70)
Fire.SecondaryColor = Color3.fromRGB(139, 80, 55)
end
end
end
end
end)
3 comments
Same with the other answer, it does nothing when touched. I will change some things.
Are there any errors in output?
You should use :FindFirstAncestorOfClass("Model") to check if there is a model ancestor