1

例: スクリプトは、あるゲーム セッションでは正常に動作しますが、別のゲーム セッションではまったく動作しません。まるで、スクリプトが削除されるか完全に無視されるランダムな可能性があるかのようです。デバウンスを取り除けば、スクリプトが再び機能する可能性は 100% になります。ここで何がうまくいかない可能性がありますか?

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)
4

1 に答える 1

0

あなたの問題は、スコープの1つです。デバウンスは常に true に設定されますが、false に戻されることがあります。変更されない場合、関数は明らかに二度と実行されません。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)

debounce の値を変更する両方のステートメントが一致することに注意してください。

于 2015-10-20T00:12:36.643 に答える