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

local function OnTouch(Player) not working?

I learned how to do speed boosts from a video about a month or two ago. Although, I want to script a block that changes colors when you step on a pad. I have an error saying that "the passed value is not a function". Here is what I have:

local Pad = script.Parent
local Blob = script.Parent.Parent

local function onTouch(Player)
Blob.BrickColor = Red
wait(0.5)
Blob.BrickColor = Orange
wait(0.5)
Blob.BrickColor = Yellow
wait(0.5)
Blob.BrickColor = Green
wait(0.5)
Blob.BrickColor = Toothpaste
wait(0.5)
Blob.BrickColor = Magnenta
wait(0.5)
end
Blob.Touched:connect(steppedOn)

2 comments

0

I'm going to edit my answer to fix the block not changing colors

0

Lol, sorry about that. If I helped you, please accept my answer, it helps a lot.

1 answer

On line 18, you're calling a function that doesn't exist

On line 4, you make a function named "onTouch". On line 18 however, you try to call a function by the name of "steppedOn", which doesn't exist.

To fix this, just rename the function or you're call. Below are the two possible fixes,

local Pad = script.Parent
local Blob = script.Parent.Parent

local function onTouch(Player)
	Blob.BrickColor = Red
	wait(0.5)
	Blob.BrickColor = Orange
	wait(0.5)
	Blob.BrickColor = Yellow
	wait(0.5)
	Blob.BrickColor = Green
	wait(0.5)
	Blob.BrickColor = Toothpaste
	wait(0.5)
	Blob.BrickColor = Magnenta
	wait(0.5)
end
Blob.Touched:connect(OnTouch)--Renamed

Or

local Pad = script.Parent
local Blob = script.Parent.Parent

local function steppedOn(Player)--Renamed
	Blob.BrickColor = Red
	wait(0.5)
	Blob.BrickColor = Orange
	wait(0.5)
	Blob.BrickColor = Yellow
	wait(0.5)
	Blob.BrickColor = Green
	wait(0.5)
	Blob.BrickColor = Toothpaste
	wait(0.5)
	Blob.BrickColor = Magnenta
	wait(0.5)
end
Blob.Touched:connect(steppedOn)

EDIT,

You're not changing the color right.

When changing the color of a brick, you need to use BrickColor.new()

Here's your final fixed script,

local Pad = script.Parent
local Blob = script.Parent.Parent

local function steppedOn(Player)--Renamed
	Blob.BrickColor = BrickColor.new("Really red")--make sure the names of the colors are right
	wait(0.5)
	Blob.BrickColor = BrickColor.new("Orange")--Not Sure what the right name is
	wait(0.5)
	Blob.BrickColor = BrickColor.new("New yeller")
	wait(0.5)
	Blob.BrickColor = BrickColor.new("Camo")
	wait(0.5)
	Blob.BrickColor = BrickColor.new("Toothpaste")
	wait(0.5)
	Blob.BrickColor = BrickColor.new("Magnenta")--Not sure the right color
	wait(0.5)
end
Blob.Touched:connect(steppedOn)

You may need to change the names of the colors to the weird names Roblox has given them.

That should fix the errors and make the brick change colors.

Good Luck!

3 comments

0

Thank you, although the block is not changing colors.

0

It still doesn't work.

0

I know, use the right colors :P

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