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

Been stuck on this for like 30 mins, someone pls help?

Asked by
Vlym 19
4 years ago
local keyCards = {
Card1 = "Reisepass",
Card2 = "Fake Reisepass"

}

local borderControlSeat = workspace.BorderControlSeat
local seat = borderControlSeat.Seat
local inspectorBool = seat.InspectorBool
local keycardCheck = workspace.KeycardCheck
local cardPos1 = workspace.CardPos1
local cardPos2 = workspace.CardPos2
local tweenService = game:GetService("TweenService")
local info = TweenInfo.new(1,Enum.EasingStyle.Linear,Enum.EasingDirection.In)
local properties = {
CFrame = cardPos2.CFrame
}

local triggered = false
local inspectorBool = false
keycardCheck.KeycardBool.Value = false



function inspectorCheck(reisepass)
    print("reisepass touched")
    if seat:FindFirstChild("SeatWeld") ~= nil then
        print("seat weld exists")
        local inspectorChar = seat.SeatWeld.Part1.Parent
        print(inspectorChar.Name.." seated")
        inspectorBool = true
        return inspectorChar
    end 
end

function sendKeycard2(fakeReisepass,inspectorChar)
    print("made it this far")
    fakeReisepass.Handle.Anchored = true
    fakeReisepass.Handle.CFrame = cardPos1.CFrame
    local tween = tweenService:Create(fakeReisepass.Handle, info, properties)
    tween:Play()
    wait(1.2)
    local inspectorPlayer = game.Players:GetPlayerFromCharacter(inspectorChar)
    fakeReisepass.Handle.Anchored = false
    fakeReisepass:Destroy()


end

function sendKeycard1(Reisepass,inspectorChar)
    Reisepass.Handle.Anchored = true
    Reisepass.Handle.CFrame = cardPos1.CFrame
    local tween = tweenService:Create(Reisepass.Handle,info,properties)
    tween:Play()
    wait(1.2)
    local inspectorPlayer = game.Players:GetPlayerFromCharacter(inspectorChar)
    Reisepass.Handle.Anchored = false
    Reisepass.Parent = inspectorPlayer.Backpack
end

script.Parent.Touched:Connect(function(hit)
    print("touched")
    if hit.Parent.Parent:FindFirstChild("Humanoid") then
        print("humanoid found")
        local char = hit.Parent.Parent
        local player = game.Players:GetPlayerFromCharacter(char)
        print("declared char")
        print("set trigger")
        if hit.Parent.Name == keyCards["Card2"] then
            print("found fake reisepass")
            local fakeReisepass = hit.Parent
            print("delcared fake reisepass")
            if keycardCheck.KeycardBool.Value == false then
                keycardCheck.KeycardBool.Value = true
                print("set keycard bool value")
                inspectorCheck()
            end
            if inspectorBool == true then
                local inspectorChar = inspectorCheck()
                print(inspectorChar.Name)
                fakeReisepass.Parent = workspace
                wait(0.2)
                sendKeycard2(fakeReisepass,inspectorChar)
            end
        end
        if hit.Parent.Name == keyCards["Card1"] then
            local reisepass = hit.Parent
            print(hit.Parent.Name)
            if keycardCheck.KeycardBool.Value == false then
                keycardCheck.KeycardBool.Value = true
                inspectorCheck(reisepass)
            end
            if inspectorBool == true then
                local inspectorChar = inspectorCheck()
                print(inspectorChar.Name)
                reisepass.Parent = workspace
                wait(0.2)
                sendKeycard1(reisepass,inspectorChar)
                local playerId = player.UserId
                local inspectorPlayer = game.Players:GetPlayerFromCharacter(inspectorChar)
                local thumbType = Enum.ThumbnailType.HeadShot
                local thumbSize = Enum.ThumbnailSize.Size420x420
                local content, isReady = game.Players:GetUserThumbnailAsync(playerId,thumbType,thumbSize)
                local reisepassGui = inspectorPlayer.PlayerGui:WaitForChild("ReisepassGui")
                local avatarImage = reisepassGui.TopFrame.AvatarImage
                reisepassGui.TopFrame:TweenPosition(UDim2.new(0.5, 0,0.65, 0))
                reisepassGui.BottomFrame:TweenPosition(UDim2.new(0.5, 0,0.82, 0))



            end
        end

    end
end)

Error message: Workspace.KeycardCheck.KeycardSlot.Script:86: attempt to index nil with 'Name'

This is only happening when I insert Card2 (Fake Reispass) through the key slot. Card2 successfully goes through the slot, but at the end throws the error above

0
...do you actually need to use a table? you could just use variables. iOriena3 67 — 4y
0
That doesn't help. Post relevant responses pls Vlym 19 — 4y
0
if you delete Card2 or hit.Parent 'tis gonna error lol Fifkee 2017 — 4y
0
How should the deletion of Card2 affect Card1? I checked my backpack in game, and Card1 is there along with its counterparts Vlym 19 — 4y
View all comments (2 more)
0
Try if hit.Parent:FindFirstChild("Card1") JesseSong 3916 — 4y
0
no, hit is the Handle, the Parent is the Tool @Jesse Vlym 19 — 4y

1 answer

Log in to vote
0
Answered by
Vlym 19
4 years ago

Found the solution, if anyone came across the same problem, read.

In the function starting line 61, hit is declared as the thing that hits the detector. If hit.Parent.Name == Card2 (Fake Reisepass) this means hit is the handle of Card2. Further along, Card2 ends up being destroyed as expected, but this means that hit is now nil. Therefore, when the script checks if hit.Parent.Name == Card1 (Reisepass) it throws an error because hit was declared as the handle of Card2 which was destroyed. To workaround, I put a return between lines 84 and 85 which will essentially stop the function there, meaning hit will be reassigned as the function runs again

Ad

Answer this question