Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Crowbar/KeyCard door not working?

I am trying to make a door when a tool touches it allows you to walk through and the barricades will fall off.

Door Script:

function ontouch(hit)
	local Crowbar = hit:findFirstChild("Crowbar")
	if Crowbar then
		script.Parent.Transparency = 0.6
		script.Parent.CanCollide = false
	else
		print("Script Not Working")
   end
end
script.Parent.Touched:Connect(ontouch)

Barricade Script:

function ontouch(hit)
	local Crowbar = hit:findFirstChild("Crowbar")
	if Crowbar then
		script.Parent.Anchored = false
	end
end
script.Parent.Touched:Connect(ontouch)

3 comments

0

Do you know what would be super cool? If you explain w h a t w a s w r o n g

0

^

0

^

1 answer

If the problem is the crowbar not being detected, then it's probably because of the 'hit' argument returning the handle part of the crowbar already, so no need to search for the crowbar again. Just check if the handle is inside a tool named "Crowbar" or not.

local Tool = hit.Parent
if Tool and Tool.Name == "Crowbar" then
	-- do something
end

3 comments

0

Thanks

0

I am having an error when using the script " attempted to index nil with 'parent' "

0

i edited it accordingly, hopefully it should work

This discussion is preserved as it was. New answers, comments, and votes are closed.