Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can I make a players head be on fire?

So I made a little ragdoll game and wanted to make a lava thing but I don't know much about Roblox coding that much. This is what I got.

local Players = game:GetService("Players")
local lava = script.Parent

lava.Touched:Connect(function(hit)
	Players:GetPlayerFromCharacter(function(char)
		local burn = Instance.new('Fire')
		burn.Size = 3
		burn.Parent = char.Head
	end)
	
end)

Help appreciated!

2 answers

Your code is correct but your not checking if whatever touched the lava is a character. Here is the code fixed.

local Players = game:GetService("Players") --Not needed
local lava = script.Parent

lava.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then --Humanoid check
        local burn = Instance.new('Fire')
        burn.Size = 3
        burn.Parent = hit.Parent.Head
    end
end)

Also, Players:GetPlayerFromCharacter(function(char) is a built in function and not an RBXScriptSignal so it would be use like so

local Character = game.Players:GetPlayerFromCharacter(character)

3 comments

0

Same with the other answer, it does nothing when touched. I will change some things.

0

Are there any errors in output?

0

You should use :FindFirstAncestorOfClass("Model") to check if there is a model ancestor

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 -- Change this to true/false if you want only one fire at a time in the players head.
lava.Touched:Connect(function(hit)
	local model = hit:FindFirstAncestorOfClass("Model") -- Check if there is a Model object in the touched part ancestry,
	if model then -- If there is a model
		local player = Players:GetPlayerFromCharacter(model)
		if player then -- If the character is a player
			local head = model:FindFirstChild("Head")
			if head then -- Check if a head is in the players' character
				if FIRE_ONLY_ONCE then -- Check if the FIRE is allowed once only
					if not head:FindFirstChild("Fire") then -- if there is fire already inside the head, dont insert more flames
						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 -- if we are allowed multiple fire in our head 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
			end
		end
	end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.