2016-11-07 157 views
0

我試圖讓這個當你觸摸一塊磚,它會凍結你的性格,然後在ModuleScript,使一個ImageLabel然後慢慢出現運行功能當你的角色被傳送到該建築物內部/外部時消失。到目前爲止,我已經設法凍結你的角色並調用函數,但是使圖像出現和消失的代碼不起作用。這是代碼:ROBLOX的Lua - 圖像透明度功能

_G.BeginFade = {}

_G.BeginFade.GlobalFunction = function()

`local Image = game.StarterGui.Fade.FadeImage` 
Image.Visible = true 
repeat 
    Image.ImageTransparency = Image.ImageTransparency - 0.1 
    wait(0.2) 
until 
    Image.ImageTransparency == 0 
wait(2) 
repeat 
    Image.ImageTransparency = Image.ImageTransparency + 0.1 
until 
    Image.ImageTransparency == 1 

end

我用_G.BeginFade.GlobalFunction()調用函數,我把它從不同的腳本。包含該函數的ModuleScript位於StarterGui中。它返回此錯誤:你可能想看看

Workspace.Home Teleport.tele2.Teleport pad Script:47: attempt to index field 'BeginFade' (a nil value)

回答

0
local player = game.Players.LocalPlayer 
local Image = player.StarterGui.Fade.FadeImage 
local i = 0 --have i as a stopper for the repeat function, it tends to go over it. 
script.Parent.Door1.Touched:connect(function(hit) 
if hit.Humanoid ~= nil then 
Image.Visible = true 
repeat 
Image.Transparency = Image.Transparency - 0.1 
i = i + 1 
wait(0.1) 
until i == 10 
end 
end) 

script.Parent.Door2.Touched:connect(function(hit) 
if hit.Humanoid ~= nil then 
Image.Visible = true 
repeat 
Image.Transparency = Image.Transparency - 0.1 
i = i - 1 
wait(0.1) 
until i == 0 
end 
end) 
+0

謝謝,但我需要它的功能,所以我可以從其他腳本調用它。如果我把它的一部分放到一個函數中,它會起作用嗎? – Dragonshield

0

事情是,如果全球在該函數的時間宣佈,因爲如果你在一個單獨的線程聲明它存在的可能性它仍然是零。

事實上,給出的錯誤代碼與您給出的代碼片段沒有任何關係。

如果你給了我們整個模塊和你的聲明,那麼我們可以在這裏給你直接的補丁......但是直到那時纔看看你的聲明是否在線程之間同步。