如何在玩家触摸砖时检测玩家是否穿着特定的T恤[Roblox - LUA] [关闭]

问题描述 投票:-1回答:1

就像在标题中,我正在寻找一个可以做到这一点的脚本。如果有人可以修复这个脚本我会很高兴:D

function onTouched(part)
local h = part.Parent:findFirstChild("Humanoid")
if h ~= nil then
    if player.parent.torso.roblox.Texture == "https://web.roblox.com/Bloxxer-item?id=1028595" then
        script.Parent.Check.Transparency = 0
        wait (2)
        script.Parent.Check.Transparency = 1
    end
end

end script.Parent.Touched:connect(onTouched)

lua roblox
1个回答
0
投票

如果你找不到任何你想做的或可编辑的free-model;开始了:

因为我们经常引用script.Parent,所以让我们制作一个variable

local Block = script.Parent

另外,我们也可以通过为它设置变量来避免在代码体中放置像url这样的常量:

local TShirtTexture = "http://www.roblox.com/asset/?version=1&id=1028594"

请注意,T恤纹理链接与商品链接不同。我认为Bloxxer纹理是http://www.roblox.com/asset/?version=1&id=1028594。要查找链接,请在工作室中加入T恤和inspect T恤

我们还需要一个debouncer

如果你真的不需要在外面引用它,我更喜欢anonymous functions

Block.Touched:connect(function(Part)
    -- code goes here
end)

线part.Parent:findFirstChild可能是不安全的,因为part.Parent可能是nil,如果部件在触摸后但在代码运行之前被移除,所以最好先检查它(如果你因为这样射击它们,一些贵宾门会用来打破)。与其他东西相同,检查它是否存在,否则代码可能会在某些时候中断。

接下来,字符Torso大写。此外,T恤是角色,而不是玩家。并抛出一些变数

最后一切都在一起:

-- Put some variables
local Block = script.Parent
local TShirtTexture = "http://www.roblox.com/asset/?version=1&id=1028594"

-- Debounce variable
local Debounce = false

-- Use anonymous function
Block.Touched:connect(function(Part)
    -- Assume that the Part is a BodyPart, thus the parent should be the character
    local Character = Part.Parent

    -- Ensure that our assumption is correct
    if Character == nil or Character:findFirstChild("Humanoid") == nil then return end

    -- Reference to the assumed Torso
    local Torso = Character:findFirstChild("Torso")

    -- Ensure that it exists
    if Torso == nil then return end

    -- Reference to the assumed T-Shirt
    local TShirt = Torso:findFirstChild("roblox")

    -- Ensure that it exists, and that it is a Decal (T-Shirts are decals)
    if TShirt == nil or not TShirt:IsA("Decal") then return end

    -- Ensure the texture is correct
    if TShirt.Texture ~= TShirtTexture then return end

    -- Check debounce
    if Debounce then return end
    Debounce = true

    -- Do stuff
    Block.Check.Transparency = 0
    wait (2)
    Block.Check.Transparency = 1

    Debounce = false
end)

如果你想检查玩家是否拥有该物品,而不是必须佩戴它,check this out

此外,如果脚本不起作用,请记住发布相关的errors

© www.soinside.com 2019 - 2024. All rights reserved.