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

How to fix attempt to call nil value error?

Everytime I run the script and test it, it gives me the error "attempt to call a nil value". Multiple attempts to fix it but nothings working. :/

Button = workspace.TRAIN.Button

Button.Touched:Connect(OnTouch)
function OnTouch()
	wait(5)
	workspace.TRAIN.Engine.Locomotive.Drive.Throttle = 1
end

ParkButton = workspace.TrainParkTrigger

ParkButton.Touched:Connect(Touched)
function Touched()
	workspace.TRAIN.Engine.Locomotive.Drive.Throttle = 0
end

6 comments

0

What number does the error say?

0

Just literally "Attempt to call a nil value"

0

Are you able to send an image of the full error?

0

Yea - how?

0

Press Win+Shift+S, and try to take the image and post it as a link.

0

we cant really help you without more info about it ;-;

1 answer

✓ Accepted answer

Try this if this works:

Button = workspace.TRAIN.Button

function OnTouch()
    wait(5)
    workspace.TRAIN.Engine.Locomotive.Drive.Throttle = 1
end

ParkButton = workspace.TrainParkTrigger

function Touched()
    workspace.TRAIN.Engine.Locomotive.Drive.Throttle = 0
end

Button.Touched:Connect(OnTouch)
ParkButton.Touched:Connect(Touched)

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