Я хочу открыть дверь при касании игрока, если значение в стартере игроков gui истинно - PullRequest
0 голосов
/ 07 августа 2020

Когда игрок касается блока перед или за дверью, я хочу, чтобы он проверял, истинно ли значение в стартере игрока gui, и если оно, то откройте дверь, я могу сделать это при щелчке блока, но не когда часть касалась, когда я пытался. Поэтому я попытался использовать то, что я бы использовал для интерактивного кирпича, и просто изменил его на функцию касания, но это не сработало. код:

local db= false
local open = script.Parent.Open
local ind = script.Parent.Door1

script.Parent.Trigger.Touched:connect(function(player)
    if db == false then
        db = true
    if player:WaitForChild("PlayerGui").keyCard.Key.Value == true then
        if open.Value == false then
            script.Parent.Sound:Play()
            local f = script.Parent.Door1.PrimaryPart.CFrame*CFrame.Angles(0,math.rad(90),0)
            local f2 = script.Parent.Door2.PrimaryPart.CFrame*CFrame.Angles(0,-math.rad(90),0)
            for i = 0,1,0.1 do
                local cfm = script.Parent.Door1.PrimaryPart.CFrame:lerp(f,i)
                local cfm2 = script.Parent.Door2.PrimaryPart.CFrame:lerp(f2,i)
                script.Parent.Door1:SetPrimaryPartCFrame(cfm)
                script.Parent.Door2:SetPrimaryPartCFrame(cfm2)
                wait()
            end
            open.Value = true
            wait(1) -- how long the door will stay open
            local f3 = script.Parent.Door1.PrimaryPart.CFrame*CFrame.Angles(0,-math.rad(90),0)
            local f4 = script.Parent.Door2.PrimaryPart.CFrame*CFrame.Angles(0,math.rad(90),0)
            for i = 0,1,0.1 do
                local cfm = script.Parent.Door1.PrimaryPart.CFrame:lerp(f3,i)
                local cfm2 = script.Parent.Door2.PrimaryPart.CFrame:lerp(f4,i)
                script.Parent.Door1:SetPrimaryPartCFrame(cfm)
                script.Parent.Door2:SetPrimaryPartCFrame(cfm2)
                wait()
            end
            open.Value = false
        end
    else
        print("Negative")
    end
    db=false
    end

конец)

script.Parent.Trigger2.Touched:connect(function(player)
    if db == false then
    db = true
if player:WaitForChild("PlayerGui").keyCard.Key.Value == true then
        if open.Value == false then
            script.Parent.Sound:Play()
            local f = script.Parent.Door1.PrimaryPart.CFrame*CFrame.Angles(0,-math.rad(90),0)
            local f2 = script.Parent.Door2.PrimaryPart.CFrame*CFrame.Angles(0,math.rad(90),0)
            for i = 0,1,0.1 do
                local cfm = script.Parent.Door1.PrimaryPart.CFrame:lerp(f,i)
                local cfm2 = script.Parent.Door2.PrimaryPart.CFrame:lerp(f2,i)
                script.Parent.Door1:SetPrimaryPartCFrame(cfm)
                script.Parent.Door2:SetPrimaryPartCFrame(cfm2)
                wait()
            end
            open.Value = true
            wait(1) -- how long the door will stay open
            local f3 = script.Parent.Door1.PrimaryPart.CFrame*CFrame.Angles(0,math.rad(90),0)
            local f4 = script.Parent.Door2.PrimaryPart.CFrame*CFrame.Angles(0,-math.rad(90),0)
            for i = 0,1,0.1 do
                local cfm = script.Parent.Door1.PrimaryPart.CFrame:lerp(f3,i)
                local cfm2 = script.Parent.Door2.PrimaryPart.CFrame:lerp(f4,i)
                script.Parent.Door1:SetPrimaryPartCFrame(cfm)
                script.Parent.Door2:SetPrimaryPartCFrame(cfm2)
                wait()
            end
            open.Value = false
        end
    else
        print("Negative")
    end
    db=false
end
end)

1 Ответ

0 голосов
/ 07 августа 2020

Touch не дает вам плеера. Вместо того, что коснулось блока, в случае игрока - это часть игрока, которая коснулась этой части.

Рекомендуется проверить, коснулся ли это игрок:

touchedPart.Parent: FindFirstChild ("Humanoid")

Затем вы можете найти игрока с помощью службы player:

Players: GetPlayerFromCharacter (touchedPart.Parent)

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...