Script wont execute

Hi I am learning to code, This script wont execute

local part = script.Parent

local function disappear ()
part.CanCollide = false


local function appear ()
part.CanCollide = true


script.Parent = disappear()


It shows Synatx Error Expected got ‘end’ This synatx errors shows at the last end statement , i am trying to change part properties from script but it wont work please help

  1. You have an extra end. Remove the last end that’s after the script.Parent line.

  2. I don’t understand what’s this line supposed to do:

You have a function that makes the part invisible, but it returns nothing so you’re basically destroying the part. (Setting the parent to nil).

You’re basically doing this:

script.Parent = nil

If you want to run the functions just write them normally, no need for script.Parent.

Like this:

local part = script.Parent

local function disappear()
    part.CanCollide = false

local function appear()
    part.CanCollide = true
disappear() --Part.CanCollide set to false
wait(3) --Just a short delay for testing
appear() --Part.CanCollide set to true

Few other notes:

  1. The BasePart.CanCollide property won’t make it disappear or appear (unless part falls), it’ll just determine whether things can move through it (collide with it) or not).
    I suggest you to use BasePart.Transparency instead.
  2. Suggest you to read about indentation, it’ll make code more readable.

Good luck on learning to script :slight_smile: :star:


It works now thats alot for helping me out! I thought the script needs to know who it is using the function on so i did a little mistake :sweat_smile:

1 Like