What is wrong with this script

How can I fix my script

The purpose of this script is when a player touches a NPC (A invisible part)

Here is the script

function onTouch(Touch)
	print("Test")
	script.Parent.Parent.Head.face.Texture = ("http://www.roblox.com/asset/?id=7239995200")
	print("Test")
	wait(2)
	print("Test")
	script.Parent.Parent.Head.face.Texture = ("rbxasset://textures/face.png")
	print("Test")
end

The first asset gives me a 404, maybe that is what’s causing the problem. Have you tried using a different texture?
Also, there’s no need for the URLs to be surrounded in parenthesis

1 Like

function onTouch(Touch)
print(“Test”)
script.Parent.Parent.Head.face.Texture = “DisgustedFace - Roblox”
print(“Test”)
wait(2)
print(“Test”)
script.Parent.Parent.Head.face.Texture = “rbxasset://textures/face.png”
print(“Test”)
end

I edited one of them. Still doesn’t work.

is the onTouch function being called with :connect?

No.

function onTouch(Touch)

is not using :connect

Your function doesn’t run without being connected to an event or fired in some sort of way

1 Like

You need to use the :connect function if you want your function to do anything.

something like
workspace.yourBrick.Touched:connect(onTouch)
should work

don’t use deprecated methods

please use :Connect() instead of :connect()

thank you

Alright I’ll try that…

I keep getting an error

in the last put
script.Parent.Touched:Connect(onTouch)

I think it should be
Touch.Parent:FindFirstChild(“Head”).Face.Texture = The Texture id here

or maybe
if Touch.Parent:FindFirstChild(“Head”) ~= nil then
local head = Touch.Parent:FindFirstChild(“Head”)
head.Face.Texture = the texture id here

Still not working…

heres what I put in:

function onTouch(Touch)
print(“Test”)
script.Parent.Parent.Head.face.Texture = (“http://www.roblox.com/asset/?id=7239995200”)
print(“Test”)
wait(2)
print(“Test”)
script.Parent.Parent.Head.face.Texture = (“rbxasset://textures/face.png”)
print(“Test”)
script.Parent.Touched:Connect(onTouch)
end

put this outside the function, not inside it

1 Like