Tool script not functioning

I’m trying to make a barrier tool you can place around and since I’m not good at scripting I looked up a video to help and I kept watching over the video and cant figure out why it worked for him and not for me.

Warnings: image

Code around warnings:


https://gyazo.com/8d1e3572ea61dfd8c09aede8226c3a09 image

2 Likes

Did you previously define the variables earlier in the script (outside of any loops or functions) by doing

local <VariableName> 

? if you didn’t, then the script is trying to read and set an undefined variable that you didn’t establish before.

image

This is what I have the tutorial did not add anything for the ev, ev1, or ev2

1 Like

The tutorial may have been outdated, however I believe that just pre-defining the variables at the start of the script should solve the issue. Alternatively, you could just make the variables local within the function the first time you defined each of them.

Consider reading this for more info.

image
W003 on the valid was fixed but it pops up errors or becomes a W001 problem when I did it to the ev. I’m going to keep trying with it for a minute.

If I fix the W003 and W001 I get an error.

image

May I see what the lines causing the errors are?

When I fix the warnings for one then a . causes an error:

image

1 Like

Ah, one of the issues is that you’re doing ev.Disconnect() and not ev:Disconnect()

And for ev1/ev2 fixing the warnings cause the parenthesis to error

1 Like

When I fixed the . to a colon the parenthesis errored for ev aswell.

When you hover over the red underlines, what do they say?

Syntax error: Incomplete statement: expected assignment or function call.

You don’t need to put local before the variables when you do the disconnect. You only need to add the local part the first time you define them.

like this?
image

1 Like

Yes, and try replacing
local ev = <YourFunction>
with

local ev

ev = <YourFunction>

, making sure to have them on separate lines.

1 Like

Thank you. That cleared the warning and errors.