Doors that open when holding a item

is it possible to open doors while holding a item… i want the door to get transparant…
im using a simple code… idk if i can add something to it… ty for your time :slight_smile:





function onClicked()

	script.Parent.Transparency = 1
	script.Parent.CanCollide = false
	wait(4)
	script.Parent.Transparency = 0
	script.Parent.CanCollide = true
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)


it does work when im not holding a item…

assuming this script is in the door hitbox:

local cooldown = false

script.Parent.Touched:Connect(function(hit)
if cooldown == false  and hit.Parent.Name == "NAME OF THE TOOL" then
cooldown = true
	script.Parent.Transparency = 1
	script.Parent.CanCollide = false
	wait(4)
	script.Parent.Transparency = 0
	script.Parent.CanCollide = true
cooldown = false
end
end)

should work if you replace “NAME OF THE TOOL” with your item’s name

DO NOT use this, .touched events work really poorly, and this can and will cause issues in your game.
Not a good idea to use at all, not to be rude ofc

sorry im new… im still learning

what alternatives are there to .touched then?

a hitbox? sorry idk what that is

the hitbox is the actual door part that you want to make transparent

What you would need to do is get the player that clicked the door, so something like this:

local ToolName = 'NameOfToolHere'

function onClicked(Player)
    if not player.Character:FindFirstChild(ToolName) then return end
	script.Parent.Transparency = 1
	script.Parent.CanCollide = false
	wait(4)
	script.Parent.Transparency = 0
	script.Parent.CanCollide = true
end


script.Parent.ClickDetector.MouseClick:connect(onClicked)


by adding a couple lines we can tell if the player contains a tool (when a player holds a tool it goes into their character, so we just tell if they have it, in the case they dont, we use return to stop the code from running after it

@nightstatue87 try this, I replied to the wrong person lol

Its ok, I was using .Touched for ages, its just unreliable so I gotta spread the word lol

iiiiiiii it works!!! ty <3 wohooooo

1 Like

wait what??? now im lost… is this better?

Well it uses the original click detector you were using. That and it also doesnt use a .Touched.

It might not matter in the grand scheme of things, but if a player is walking or something, .Touched may not run, or if they are just moving at all for that matter, sometimes you might have to repeatedly walk into the door.

Using a click detector also has some cons I think, but its much more accurate than using a .Touched event to my knowledge, so it may be the way to go. Ofc thats up to you!

tysm <3 i will try to read about it :slight_smile:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.