2016-08-20 39 views
0

就像在標題中一樣,我正在尋找一個可以做到這一點的腳本。如果有人可以修復這個劇本我會很高興:d如果玩家在觸摸磚塊時穿上特定的T恤,該如何檢測[Roblox - LUA]

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 

末 script.Parent.Touched:連接(onTouched)

回答

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如果一部分接觸之後,但在代碼運行之前去除,所以最好先檢查一下它(用了一些VIP門打破,如果你拍因爲這個)。與其他東西一樣,檢查它是否存在,否則代碼可能會在某些時候中斷。

接下來,字符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

+0

我在我的世界嘗試它,腳本不工作。我試圖改變T恤ID一點,看看是否有錯誤,但它仍然無法正常工作。 – AirportStaff

+0

@AirportStaff是否有錯誤? Block.Check是否正確?通常你沒有零件 – ZombieSpy

+0

我不知道爲什麼,但有人編輯我的問題,並添加一個「檢查」因爲沒有在我的第一個問題。但是,無論如何,我刪除「檢查」,現在它工作! – AirportStaff