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

(Easy) My script wont print when a part in workspace is touched?

Asked by 4 years ago

it's underlines end) I don't know whats wrong

local CFrameTester = script.Parent

if script.Parent.Parent.Tester1.Touched:Connect(function()

        print("it worked!")

    end)

0
DO NOT add an if when checking if a part was touched mixgingengerina10 223 — 4y
0
You didn't call the function. after the end put " ScriptsALot 91 — 4y
0
Instead of an if statement use a function. "function partTouched (onTouch) ScriptsALot 91 — 4y
0
and then after the function put "script.Parent.Parent.Tester1.Touched:Connect(partTouched)" ScriptsALot 91 — 4y

2 answers

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

Your mistake was really simple: do NEVER put an if statement if you are making a function. That being said, just remove the if statement and you will be good to go!

local CFrameTester = script.Parent

script.Parent.Parent.Tester1.Touched:Connect(function()

        print("it worked!")

    end)

Ad
Log in to vote
0
Answered by 4 years ago

This is very simple. So insert a part in the workspace and insert a script in the part and type this

Script

local function onTouch(hit)
    print("it worked!")
end

script.Parent.Touched:Connect(onTouch)

Now when you touch it, it will print "It Worked"

Answer this question