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

local function OnTouch(Player) not working?

Asked by 8 years ago

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)
0
I'm going to edit my answer to fix the block not changing colors User#11440 120 — 8y
0
Lol, sorry about that. If I helped you, please accept my answer, it helps a lot. User#11440 120 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

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!

0
Thank you, although the block is not changing colors. Danielch1234 20 — 8y
0
It still doesn't work. Danielch1234 20 — 8y
0
I know, use the right colors :P User#11440 120 — 8y
Ad

Answer this question