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

script returns attempt to call nil value?

Asked by 3 years ago

note: the output only says server, but i think it is the script below cuz it says time to fix that right after ;error might be from line 14

i am making a block that when touched will see if it is a player's car touching or a bot's car touching, then if it is a player it will teleport the player to a certain location

here is the script inside the block

local the_big_boi = script.Parent

local function onPartTouched(other_part)
    if other_part.parent.properties ~= nil then -- finds out if the touching model is a car
        if other_part.parent.properties.person_in_car.Value == "bot" then
            print("person is bot")
            local bot = other_part.Parent
            bot.humanoid.Health = 0
            bot:destroy()
        else
            print("person is you know a person")
            local car = other_part.parent
            wait(1)
            car.touch_block.respawn_script.trigger_script.Value = true
            print("welp time to fix that ^")
        end
    else

    end
end

the_big_boi.Touched:Connect(onPartTouched)

1 answer

Log in to vote
0
Answered by 3 years ago

The reason why it says the value is nil is because when ANY part touches it the event activates, so you have to put a :WaitForChild() block in that line.

Your code looks like this:

local the_big_boi = script.Parent

local function onPartTouched(other_part)
    if other_part.parent.properties ~= nil then -- finds out if the touching model is a car
        if other_part.parent.properties.person_in_car.Value == "bot" then
            print("person is bot")
            local bot = other_part.Parent
            bot.humanoid.Health = 0
            bot:destroy()
        else
            print("person is you know a person")
            local car = other_part.parent
            wait(1)
            car:WaitForChild("touch_block").respawn_script.trigger_script.Value = true
            print("welp time to fix that ^")
        end
    else

    end
end

the_big_boi.Touched:Connect(onPartTouched)

Feel free to list any errors in comments!

Ad

Answer this question