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

Whats causing my script to not produce any results?

Asked by 4 years ago

Hello, recently i've been working on a fire and water script in which someone jumps into lava and takes damage, then jumps into the water and clears all the effects from the fire. This is my script for both.

local firePart = script.Parent
local Players = game.Players

firePart.Transparency = 1

local Lava = function(hitPart)
    if hitPart.Parent:FindFirstChild("Humanoid") then
        hitPart.Parent.Humanoid.Health = hitPart.Parent.Humanoid.Health - 3

        if hitPart.Parent.Humanoid.Health > 0 then
            local Parts = hitPart.Parent:GetChildren()
            for i, Parts in pairs(Parts) do
                if Parts:IsA("BasePart") then
                    Instance.new("Fire", Parts)
                    Instance.new("Smoke", Parts)

                end
            end

        end
    end
end

firePart.Touched:Connect(Lava)

thats my Fire script, and this next one is my water script

local waterPart = script.Parent
waterPart.Transparency = 1
local function PutOutFire(part)
local   human = part:FindFirstChild("Humanoid")

for i, human in pairs(human) do
    if human:FindFirstChild("Smoke") then
        human:FindFirstChild("Smoke"):Destroy()

    end
    if human:FindFirstChild("Fire") then
        human:FindFirstChild("Fire"):Destroy()
    end
end
    end
waterPart.Touched:connect(PutOutFire)

I am not sure where am going wrong, I don't get any errors, but the smoke and fire effect from the fire script doesn't leave even after I jump into the water. What do I need to change, and how can I make this better? Help will be much appreciated.

1 answer

Log in to vote
0
Answered by
Robowon1 323 Moderation Voter
4 years ago

You're looking for humanoid in the part hit, and checking for smoke and fire in the humanoid(which is nil)

fix:

local waterPart = script.Parent
waterPart.Transparency = 1
local function PutOutFire(part)
if part.Parent.Humanoid then
local human = part.Parent:GetChildren()


for i, human in pairs(human) do
    if human:FindFirstChild("Smoke") then
        human:FindFirstChild("Smoke"):Destroy()

    end
    if human:FindFirstChild("Fire") then
        human:FindFirstChild("Fire"):Destroy()
    end
end
    end
end
waterPart.Touched:connect(PutOutFire)
0
whoooo, it worked! I have a few questions about it though, for example do you mean Humanoid is nil? If so, how do I know if it is or not? Sorry am kinda noob at this. dragonspade21 15 — 4y
0
when referencing an object with an if statement the code is just returning a boolean value(true or false) on whether the object is not nil, if the if statement detects true then it runs the code under it Robowon1 323 — 4y
0
Alright, thanks for the explanation dragonspade21 15 — 4y
0
np Robowon1 323 — 4y
Ad

Answer this question