Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I make a players head be on fire?

Asked by 4 years ago

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

Log in to vote
0
Answered by
uhi_o 417 Moderation Voter
4 years ago
Edited 4 years ago

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)
0
Same with the other answer, it does nothing when touched. I will change some things. Adv_xnced 0 — 4y
0
Are there any errors in output? uhi_o 417 — 4y
0
You should use :FindFirstAncestorOfClass("Model") to check if there is a model ancestor FunctionalMetatable 490 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

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)

Answer this question