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

Could this work?

Asked by 10 years ago
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.

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. BlueTaslem 18071 — 10y
0
How would I write it so both would happen at the same time when a player touches the brick? bloonblaster2000 55 — 10y
0
Will this work? bloonblaster2000 55 — 10y

3 answers

Log in to vote
1
Answered by
Ekkoh 635 Moderation Voter
10 years ago
  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)
0
Do I put it in a LocalScript? bloonblaster2000 55 — 10y
0
It wouldn't work in a LocalScript. I recommend reading about LocalScripts to clear up any questions you have. Ekkoh 635 — 10y
Ad
Log in to vote
0
Answered by
Dummiez 360 Moderation Voter
10 years ago

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)
0
That would never work because you're comparing Part.Parent.Name (a string value) to game.Players:FindFirstChild(Part.Parent.Name) (an Instance) Ekkoh 635 — 10y
Log in to vote
0
Answered by 10 years ago

@Dummiez

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

Answer this question