如何修复我在Roblox Lua中制作的脚本?

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

我正在编写脚本和脚本分析工具

错误:(54,2)预期,得到'结束'

我想也许你们可能会帮忙。这是代码

-- to be placed in StarterPlayer > StarterPlayerScripts

local Players = game:GetService("Players")

-- wait for local player PlayerGui
local LocalPlayer = Players.LocalPlayer
local playerGui = LocalPlayer:WaitForChild("PlayerGui")

-- create a ScreenGui
local screenGui = Instance.new("ScreenGui", playerGui)

-- create a holder for our bar
local frame = Instance.new("Frame", screenGui)
frame.AnchorPoint = Vector2.new(0.0, 0.0)
frame.Position = UDim2.new(0.0, 0, 0.0, 0)
frame.Size = UDim2.new(0.0, 0, 0.0, 0)
-- create a bar
local bar = Instance.new("Frame", frame)
bar.Position = UDim2.new(0, 0, 0, 0)
bar.Size = UDim2.new(1, 0, 1, 0)
bar.BackgroundColor3 = Color3.new(0, 1, 0)

-- create a sound
local sound = Instance.new("Sound", screenGui)
local lastLoudness = 0
sound.SoundId = "rbxassetid://697821987"
sound.Looped = true
sound:Play()

-- define a max loudness
local maxLoudness = 30

-- animate the amplitude bar
while true do
    local amplitude = math.clamp(sound.PlaybackLoudness / maxLoudness, 0, 1)    
    print(80-(game.Workspace.CurrentCamera.FieldOfView))
    bar.Size = UDim2.new(sound.PlaybackLoudness / maxLoudness, 0, 0, 0)
    wait(0.00001)
        local lastLoudness = 0
            local PBS = ((sound.PlaybackLoudness/50)^(sound.PlaybackLoudness/50))
            if lastLoudness~=0 then
                local formula = math.abs((lastLoudness*15)) + ((lastLoudness+PBS)/1.9)
                if (math.abs(PBS) > formula) == true then
                    game.Workspace.CurrentCamera.FieldOfView = (lastLoudness)
                    if game.Workspace.CurrentCamera.FieldOfView <= 10 then
                    print(formula, PBS) 
                    else
                    game.Workspace.CurrentCamera.FieldOfView = 0
                    print(formula, PBS)
                    end
                end
            end
        end
    end
end

我真的不知道如何修复代码,所以......你们能帮助我吗?我在这上花了很长时间(几个小时),我合法地陷入了编码地狱的最深处。我希望这个固定得很糟糕。另外,Just To Clarify,当声音时,脚本应该改变FOV.PlaybackLoudness÷50×sound.PlaybackLoudness÷50超过0。

lua eof roblox
1个回答
2
投票

Egor Skriptunoff是对的。让我重新格式化你的while循环以告诉你原因。

-- animate the amplitude bar
while true do
    local amplitude = math.clamp(sound.PlaybackLoudness / maxLoudness, 0, 1)    
    print(80-(game.Workspace.CurrentCamera.FieldOfView))
    bar.Size = UDim2.new(sound.PlaybackLoudness / maxLoudness, 0, 0, 0)
    wait(0.00001)
    local lastLoudness = 0
    local PBS = ((sound.PlaybackLoudness/50)^(sound.PlaybackLoudness/50))

    if lastLoudness~=0 then
        local formula = math.abs((lastLoudness*15)) + ((lastLoudness+PBS)/1.9)
        if (math.abs(PBS) > formula) == true then
            game.Workspace.CurrentCamera.FieldOfView = (lastLoudness)
            if game.Workspace.CurrentCamera.FieldOfView <= 10 then
                print(formula, PBS) 
            else
                game.Workspace.CurrentCamera.FieldOfView = 0
                print(formula, PBS)
            end
        end
    end
end
end --  <-- these bad boys don't go with anything
end --  <-- just remove them to get rid of the error

编辑:这是一个更完整的答案,以帮助您解决其他脚本问题。您正在将动画内容调整为0像素高,因此您无法看到任何内容。

-- to be placed in StarterPlayer > StarterPlayerScripts

local Players = game:GetService("Players")

-- wait for local player PlayerGui
local LocalPlayer = Players.LocalPlayer
local playerGui = LocalPlayer:WaitForChild("PlayerGui")

-- create a ScreenGui
local screenGui = Instance.new("ScreenGui", playerGui)

-- create a holder for our bar
local frame = Instance.new("Frame", screenGui)
frame.AnchorPoint = Vector2.new(0.0, 0.0)
frame.Position = UDim2.new(0.0, 0, 0.0, 0)
frame.Size = UDim2.new(1.0, 0, 0.0, 50) -- <-- this is no longer invisible

-- create a bar
local bar = Instance.new("Frame", frame)
bar.Position = UDim2.new(0, 0, 0, 0)
bar.Size = UDim2.new(1, 0, 1, 0)
bar.BackgroundColor3 = Color3.new(0, 1, 0)

-- create a sound
local sound = Instance.new("Sound", screenGui)
local lastLoudness = 0
sound.SoundId = "rbxassetid://697821987"
sound.Looped = true
sound:Play()

-- define a max loudness
local maxLoudness = 30.0 -- <-- this needed to be a decimal value
local lastLoudness = 0

-- animate the amplitude bar
while true do
    -- PlaybackLoudness values range from 0 to 500, so downscale it
    local sampledLoundness = (sound.PlaybackLoudness / 50)
    local amplitude = math.clamp(sampledLoundness / maxLoudness, 0, 1)
    print("sound values : ", sound.PlaybackLoudness, maxLoudness, amplitude)

    -- animate the bar
    bar.Size = UDim2.new(amplitude, 0, 1, 0) -- <-- this was squashed to 0 pixels
    wait(0.00001)

    -- create a camera shake effect
    -- NOTE - not sure what the expected behavior is here, it just zooms in
    local PBS = sampledLoundness ^ sampledLoundness
    if lastLoudness ~=0 then
        local formula = math.abs(lastLoudness * 15) + ((lastLoudness + PBS) / 1.9)
        if (math.abs(PBS) > formula) == true then
            game.Workspace.CurrentCamera.FieldOfView = lastLoudness
            if game.Workspace.CurrentCamera.FieldOfView <= 10 then
                print("FOV is less than 10 : ", formula, PBS) 
            else
                game.Workspace.CurrentCamera.FieldOfView = 0
                print("FOV forced to 0 : ", formula, PBS)
            end
        end
    end

    -- update lastLoudness and loop
    lastLoudness = sampledLoundness
end
© www.soinside.com 2019 - 2024. All rights reserved.