Does anyone know how to fix this?

I’m extremely new to scripting and I tried this script that I thought would work. I’m trying to make a door that when you touch it, you can go through it. Does anyone know how to fix it up?

local Humanoid:Ontouched

if
Humanoid:Ontouched()
workspace.Part.CanCollide = false
workspace.Part.Transparency = 0.5
wait(2)
workspace.Part.CanCollide = true
workspace.Part.Transparency = 0

end

1 Like

Your script is wrong you should use this script:

Workspace.Part.Touched:Connect(function()
      -- your code here
end)

Okay, thanks! It works perfectly now!

Mind explaining how you found Humanoid:OnTouched? This function is never written in the devhub.

Hi again!

You are not using the .Touched event correctly. Due to it being an event, it is not an if statement. The humanoid variable is also defined incorrectly.

However, you’ve got the properties of the part correct, good job on that!

In order to use a .Touched event, you will need to write what part will be touched. I am assuming that this script is running in workspace, judging by the “workspace.Part”. So for this, I will be using “workspace.Part”:

workspace.Part.Touched:Connect(function()

In order to make this easier, if all parts in workspace have the same name as “Part”, you can also place a script in the part you want the touched event on and use script.Parent. script means that exact script you are currently writing on, and Parent means what the script is under.

You will now place your code that changes the properties of the instance inside the touched event, so:

workspace.Part.Touched:Connect(function()
workspace.Part.CanCollide = false
workspace.Part.Transparency = 0.5
wait(2)
workspace.Part.CanCollide = true
workspace.Part.Transparency = 0
end)

You will also need to add an end) at the end of the event!

1 Like

Also, if you want to write an if-then script you may:

if  then
--code
end

I don’t really know to be honest. I have heard “Ontouched” before so I used it.

May I message you on discord or here so I can teach you some scripting?

Sure! We can do it on discord. My user & tag is, poppy :yum:#1424

Check your friend requests.

Sjdhdbdsses