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

How do I make objects have a relation with "math.random"?

So, I'm making a script. What it does, is when I step on a brick, my player's bodypart(left leg, right leg, left arm, right arm) catches fire for 2 seconds and then is destroyed. What I want to do, is to make the bodyparts chosen randomly to catch fire. On top of this, I also, want it to sense if a previous body part is even there. Here's what I have:

local part = script.Parent
local db = true

function burn(hit)
	local bodypart1 = hit.Parent:FindFirstChild("Left Arm")
	local bodypart2 = hit.Parent:FindFirstChild("Right Arm")
	local bodypart3 = hit.Parent:FindFirstChild("Left Leg")
	local bodypart4 = hit.Parent:FindFirstChild("Right Leg")
	local fire = Instance.new("Fire")
	local human = hit.Parent:FindFirstChild("Humanoid")
	
	if human then
		db = false
		
		
		fire.Parent = bodypart1
		wait(2)
		bodypart1:Destroy()
		
                if bodypart1 = nil then
                fire.Parent = bodypart2
                wait(2)
                bodypart2:Destroy()
	
   end
end


part.Touched:connect(burn)

Some how, my script doesn't work. Any ideas? All help is appreciated!

1 answer

✓ Accepted answer
local part = script.Parent
local db = true

function burn(hit)
BodyParts = {}
 local bodypartLL = hit.Parent:FindFirstChild("Left Arm")
   local bodypartRR = hit.Parent:FindFirstChild("Right Arm")
  local bodypartL = hit.Parent:FindFirstChild("Left Leg")
    local bodypartR = hit.Parent:FindFirstChild("Right Leg")
    local fire = Instance.new("Fire")
    local human = hit.Parent:FindFirstChild("Humanoid")
table.insert(BodyParts{"bodypartLL.Name,bodypartRR.Name,bodypartL.Name,bodypartR.Name})

if human then
	db = false
	fire.Parent = math.random(#BodyParts)
	if fire.Parent.Name == BodyParts then
		table.remove(BodyParts{fire.Parent})
		wait(2)
      		bodypart1:Destroy()
end
	if fire.Parent == nil then
	fire.Parent = math.random(#BodyParts)
	if fire.Parent.Name == BodyParts then
		table.remove(BodyParts{fire.Parent})
		wait(2)
		fire.Parent:Destroy()
	end

end

end

part.Touched:connect(burn)

Idk if this will work. I just went from the top of my head. I changed the variables because you cannot have numbers in the Varaible. Wiki page.

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