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

Scanning door w/ pad script?

Asked by 10 years ago

So basically I need to make a door with a pad and what I need it to do is when a player stands on the pad it scans them and if they are the right team it opens but if they aren't it just says error, eg. this is a police door so a police man stands on the little scanning pad then the door opens because its a police door, but if a criminal or another type of leaderboard name stands on it, it says error, so yeah I basically need a scan pad and a door script if that is possible, :)

0
Don't ask for scripts, ask for help. TheLuaWeaver 301 — 10y

1 answer

Log in to vote
0
Answered by 10 years ago

First of all what I suggest to do is a String table which contains all of the teams, I would define it like this: teams = { "Police", "Criminal", "Civilian", "Alien" } After this I need to do a function that get called every second, this function checks the player's team:

local players = game.Players:GetChildren()
local playerteam
teams = {"Police", "Criminal", "Civilian", "Alien"}
function onUpdate()
    for _, player in pairs(players) do
        local team = player:FindFirstChild("Team")
        for _, t in pairs(teams) do
            if team.Value == t.Value then
                playerteam = t.Value
            end
        end
    end
    wait(1)
    onUpdate()
end

After this I can finally make the door script, so add this down:

function onDoorTouched(part)
    if part.Parent.Name == playerteam then
        part.Transparency = 0.5
        part.CanCollide = false
    else
        // error code here
    end
end

Now we need to call this function on EVERY door of the game, so I suggest you to do something like this: game.Workspace.Doors.TEAM.door1/door2/door3/etc. Examples:

--Civilian's doors
game.Workspace.Doors.Civilian.door1
game.Workspace.Doors.Civilian.door2
game.Workspace.Doors.Civilian.door7
[...]
--Police's doors
game.Workspace.Doors.Police.door5
[...]

WARNING: name the team's models AS SAME AS the teams in the array (the table "teams") After this we need to make the script =) Put this under everything, it isn't a function!! Just put it under everything!

for _, team in pairs (teams) do
    for _, door in pairs (team:GetChildren()) do
        local path = game.Workspace
        local door_path = team.door
        door_path.Touched:Connect(onDoorTouched)
    end
end

That's ONLY the door code, since I'm hurrying I can't now explain you how to do the Scan Pad script, sorry! Ps: the script may gives problems/crashes, write me in a PM the stacktrace (the errors in the output).

PPs: Remember to define a StringValue into the player! Name it "Team"!

Ad

Answer this question