Ryfiles
(Ryfiles)
July 17, 2020, 2:58am
#1
Hello.
I am having a problem with my keycard door.
There is no error.
Code:
script.Parent.Touched:Connect(function(Hit)
if Hit.Parent.Name == 'KeyCard' then
script.Parent.CanCollide = false
else
script.Parent.CanCollide = true
end
end)
And I touched the door, and it does not work.
2 Likes
Are you sure you hit the door with a tool named KeyCard?
Whatâs the part name inside the tool. I assume you have the tool named keycard and not the actual part thatâs touching it.
1 Like
Ryfiles
(Ryfiles)
July 17, 2020, 3:03am
#4
It has a part named Handle
inside of the tool
2mzh
(Scripter)
July 17, 2020, 3:03am
#5
Your error is here:
if Hit.Parent.Name == âKeyCardâ then
You should be referencing the KeyCardâs name instead of the parent, simply change it to:
"If Hit.Name == âKeyCardâ then âŚ(rest of your code)
Avvalor
(avv)
July 17, 2020, 3:05am
#6
local debounce = false
script.Parent.Touched:Connect(function(Hit)
if debounce then return end
debounce = not debounce
if Hit.Parent.Name == 'KeyCard' then
script.Parent.CanCollide = false
else
script.Parent.CanCollide = true
end
wait(.5)
debounce = not debounce
end)
1 Like
Nvm I apologize I read your code wrong. You were doing hit.parent nvm ignore me
1 Like
Avvalor
(avv)
July 17, 2020, 3:07am
#8
Hit.Parent is referring to the tool itself. The hit is the handle part.
2mzh
(Scripter)
July 17, 2020, 3:14am
#9
Then unless there was something misspelled, the script should work correctly.
Avvalor
(avv)
July 17, 2020, 3:19am
#10
Without a debounce, it would just repeatedly change the partâs CanCollide to true/false whenever .Touched is firedâŚ
2 Likes
If hit.Parent.Name ~= âKeyCardâ then maybe try adding this
if(hit.Name == "KeyCard" or hit.Parent.Name == "KeyCard") then
ANd as stated above, a debounce would also be the way to go here,
I agree with Avvalor. 30 CHARRRSSSS
1 Like
Ryfiles
(Ryfiles)
July 17, 2020, 3:50am
#13
Tried that and it does not work.
Avvalor
(avv)
July 17, 2020, 3:58am
#14
Have you tried this? It should work.
3 Likes
Ryfiles
(Ryfiles)
July 17, 2020, 4:00am
#15
It does not work.
[30characters]
Avvalor
(avv)
July 17, 2020, 4:04am
#16
I tried it myself in studio and it does work. Make sure to create a tool, name it âKeyCardâ and put a part named âHandleâ inside of it.
1 Like
Ryfiles
(Ryfiles)
July 17, 2020, 4:06am
#17
Never mind it works.
[30chars]
Avvalor
(avv)
July 17, 2020, 4:12am
#18
Make sure to mark the solution.