Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Crowbar/KeyCard door not working?

Asked by 4 years ago

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)
0
Do you know what would be super cool? If you explain w h a t w a s w r o n g Ziffixture 6913 — 4y
0
^ EmbeddedHorror 299 — 4y
0
^ ProjectInfiniti 192 — 4y

1 answer

Log in to vote
0
Answered by
Luathron 185
4 years ago
Edited 4 years ago

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
0
Thanks SyncSim 4 — 4y
0
I am having an error when using the script " attempted to index nil with 'parent' " SyncSim 4 — 4y
0
i edited it accordingly, hopefully it should work Luathron 185 — 4y
Ad

Answer this question