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
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)
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
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
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!