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

Could this work?

function onTouch(Part)
Instance.new ("Fire", game.Workspace.Part
wait(0.00001)
Player:findFirstChild("Humanoid").Health = 0
wait(0.00001)
game.Workspace.Part.Fire.Enabled = true
wait(5)
game.Workspace.Part.Fire.Enabled = false
end

script.Parent.Touched:connect(onTouch)

Im wondering if this would insert a fire into the brick and also kills at the same time when touched.

3 comments

0

I believe so, nonetheless, your second function is very wrong. "Player" is not defined. In addition, FindFirstChild has no purpose there since it's not actually being used for error handling.

0

How would I write it so both would happen at the same time when a player touches the brick?

0

Will this work?

3 answers

✓ Accepted answer
  1. Parameter
  2. Part is your variable name for the part that touches brick. You have to find the player/character through this part.
  3. wait(0.00001) is such a short time that the thread will yield for one frame anyway, so I'd just say wait(0) for the shortest amount of time possible if that's what you're going for.
local brick = script.Parent

function onTouch(Part) -- Declare our function onTouch where 'Part' is the part that touches 'brick'
	local fire = Instance.new ("Fire", Part) -- Create's fire in the part that touches 'brick'
	wait(0) -- Waits one frame (extremely short amount of time)
	local hum = Part.Parent:FindFirstChild("Humanoid") -- looks for a Humanoid in 'Part.Parent'
	if hum then -- If the Humanoid exists (if a Character has touched 'brick')
		hum.Health = 0 -- Set the health of that Humanoid to 0
	end -- Close 'if' scope
	wait(5)
	if fire then -- If after 5 seconds 'fire' still exists, then
		fire:Destroy() -- Remove the fire
	end
end

brick.Touched:connect(onTouch)

2 comments

0

Do I put it in a LocalScript?

0

It wouldn't work in a LocalScript. I recommend reading about LocalScripts to clear up any questions you have.

Perhaps you should define the player or search if it contains a humanoid.

local brick = script.Parent

function onTouch(Part)
	if Part.Parent:findFirstChild("Humanoid") and Part.Parent.Name == game.Players:FindFirstChild(Part.Parent.Name) then
		local fire = Instance.new ("Fire", script.Parent)
		wait(0)
		Part.Parent:findFirstChild("Humanoid").Health = 0
		wait(5)
		fire:Destroy()
	end
end
brick.Touched:connect(onTouch)

1 comment

0

That would never work because you're comparing Part.Parent.Name (a string value) to game.Players:FindFirstChild(Part.Parent.Name) (an Instance)

@Dummiez

Wouldn't it be wait() if you want to wait for the shortest time possible?

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