【问题标题】:coI want to open a door on player touch if a Value in the players startergui is true如果玩家 startergui 中的值为真,我想在玩家触摸时打开一扇门
【发布时间】:2020-11-27 08:35:08
【问题描述】:

当玩家触摸门前或门后的一个块时,我希望它检查玩家启动器 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)

【问题讨论】:

    标签: lua roblox


    【解决方案1】:

    触摸不会给你播放器。更确切地说是什么触及了障碍物,如果是玩家,则指触碰该部分的玩家的部分。

    建议您检查是否是玩家触摸:

    touchedPart.Parent:FindFirstChild("Humanoid")

    然后就可以使用播放器服务找到播放器了:

    玩家:GetPlayerFromCharacter(touchedPart.Parent)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-08-05
      • 1970-01-01
      • 2021-12-28
      • 1970-01-01
      • 2014-01-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多