Script Error (Probably very easy for you guys to fix)

I want to make it so that when a player touches a door the door allows them to go through then closes by itself. So I wrote up this script and it won’t work. (Keep in mind i’m a noob and this is my first script I wrote all by myself)

game.workspace.Parent.Part = game.Door

game.workspace.Part.Touched:Connect(fucntion()
	
	Door.CanCollide = false
	Door.Transperency = .5
	wait(3)
	Door.CanCollide = true
	Door.Transparency = .5
	
end)

Error code: Workspace.Door.Script:5: Expected ‘)’ (to close ‘(’ at line 3), got ‘Door’ - Studio - Script:5

1 Like

I don’t know if it’s specifically the reason, but you spelt function wrong.

2 Likes

HA omg i’m an idiot


I don’t think “workspace.Parent” is right.

You spelt function wrong since it says “at line 3” also its a good idea to use local when making varibles

1 Like
local Door = game.Workspace.Door

Door.Touched:Connect(function()
	
	Door.CanCollide = false
	Door.Transperency = .5
	wait(3)
	Door.CanCollide = true
	Door.Transparency = .5
	
end)
2 Likes

OHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
I get it now. I totally messed up the variable :stuck_out_tongue:

local Door = workspace.Door

why do people do game.Workspace instead of workspace, it is faster

2 Likes

There are no error codes but the script still doesn’t work…

You have a few issues,

local part = workspace.Part
local debounce = false
part.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        if not debounce then
            Door.CanCollide = false
            debounce = true
	        Door.Transperency = .5
	        wait(3)
	        Door.CanCollide = true
	        Door.Transparency = .5
            debounce = false
        end
    end
end)

You spelled function wrong, part isn’t defined correctly (doing workspace instead of game.Workspace works to), and you need to check if there is actually a player touching the part instead of anything. Let me know if you have any other questions.

2 Likes

I’ve seen debounce before though I’m not entirely sure what it is used for… Could you explain?

Well, yes, obviously, I just didn’t want to do it there.

It just makes ure you don’t end up spamming the server with multiple functions. If you did

part.Touched:Connect(function(hit)
    print("Something")
end)

This will constantly spam “Something” so you add a debounce so it won’t spam.

1 Like

It prevents something from happening for a certain period of time. Its a cooldown.

1 Like

Ah alright cool thx


Though the transparency of the door isn’t changing… And the door always stays open, I tested it pushing a part around into the door.

Edit: nvm I spelled transparency wrong