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

script returns attempt to call nil value?

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

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!

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