2015-10-13 76 views
1

例如:腳本在一個遊戲會話中工作正常,但在另一個遊戲會話中,它完全不起作用;就好像腳本被刪除或完全忽略的某種偶然機會一樣。如果我刪除了debounce,腳本再次有100%的機會再次運行。這裏可能會出現什麼問題?Roblox中的腳本工作正常,但是一旦我添加了去抖動,它仍然可以完美運行,但是有時只有這樣?

local radius = script.Parent 
local light = radius.Parent.Light 
local sound = radius.Parent.lighton 

local debounce = false 

radius.Touched:connect(function(hit) 
    if debounce == false then debounce = true 
     if game.Players:GetPlayerFromCharacter(hit.Parent) then 
      light.PointLight.Brightness = 10 
      light.Material = "Neon" 
      sound:Play() 
      wait(5.5) 
      light.PointLight.Brightness = 0 
      light.Material = "Plastic" 
      sound:Play() 
      wait(0.5) 
      debounce = false 
     end 
    end 
end) 

回答

0

你的問題是範圍界定問題之一。去抖動總是被設置爲真,但有時會被設置爲假。如果它沒有改變,該功能顯然不會再次運行。你會想要避免像if debounce == false then debounce = true這樣的行,因爲它們讓你更難注意到在同一範圍內的去抖動沒有改變。

固定碼:

local radius = script.Parent 
local light = radius.Parent.Light 
local sound = radius.Parent.lighton 

local debounce = false 

radius.Touched:connect(function(hit) 
    if debounce == false then 
     debounce = true 
     if game.Players:GetPlayerFromCharacter(hit.Parent) then 
      light.PointLight.Brightness = 10 
      light.Material = "Neon" 
      sound:Play() 
      wait(5.5) 
      light.PointLight.Brightness = 0 
      light.Material = "Plastic" 
      sound:Play() 
      wait(0.5) 
     end 
     debounce = false 
    end 
end) 

注意,這兩個語句改變反跳對齊的價值。

相關問題