Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

'st'(a boolean value) ?

Asked by 6 years ago

--Game is FE keep getting this error: Players.Player1.PlayerGui.ClientScripts.MG_MusicControl:192: attempt to index local 'st' (a boolean value)

local LOBBY_MUSIC = { "rbxassetid://170830784", }

local Settings = { VolumeDropRate = 0.25, VolumeRaiseRate = 2,

LobbyVolume = 0.5,
GameVolume = 0.6,
RoundStartEndVolume = 0.7,

RadioVolume = 0.4,

}

--Getting client data manager variables while not _G.ClientDataReady do wait() end local CLIENT_DATA = _G.CLIENT_DATA

--Common variables local player = game.Players.LocalPlayer local camera = game.Workspace.CurrentCamera local RenderStepped = game:GetService("RunService").RenderStepped

local content_provider = game:GetService("ContentProvider")

local function GetPlayerStatus() if CLIENT_DATA["SessionData"] ~= nil then local get_status = CLIENT_DATA.SessionData.RoundData["PlayerStatus"] if type(get_status) == "table" then if get_status[player.Name] ~= nil then return unpack(get_status[player.Name]) --is_alive, in_game end end end return false, false end

local function GetInGameStreams() if CLIENT_DATA["SessionData"] ~= nil then local get_streams = CLIENT_DATA.SessionData.RoundData.RoundMusicSet local get_type = CLIENT_DATA.SessionData.RoundData.MusicType return get_streams, get_type end return {}, "" end

local function CheckIfRoundEnd() if CLIENT_DATA["SessionData"] ~= nil then --return CLIENT_DATA.SessionData.RoundData.ShowRewards return (not CLIENT_DATA.SessionData.GameModeRunning) or CLIENT_DATA.SessionData.RoundData.ShowRewards end return false end

function ScrambleArray(arr) local arr_len = #arr for i = 1, arr_len - 1 do local old_val = arr[i] local sel_key = math.random(i, arr_len) arr[i] = arr[sel_key] arr[sel_key] = old_val end return arr end

--streams local SelectedStream = {"", ""}

local MUSIC_STREAMS = { Lobby = {

},
InGame = {

},
    stream_name = {
        stream_volume = 0,
        volume_type = 1,
        stream_sleeping = true,
        playback_responce = false,
        current_sound = nil,
        sound_num = 1,
        stream_list = {"rbxassetid://170830784", "", ""}
    }

}

local function CreateStream(st_type, st_name, vol_type, st_list) local NewSound = Instance.new("Sound") NewSound.Parent = script NewSound.Name = st_type .. "_" .. st_name NewSound.Volume = 0

if #st_list > 0 then
    content_provider:Preload(st_list[1])
    NewSound.SoundId = st_list[1]
    if st_list[2] ~= nil then
        content_provider:Preload(st_list[2])
    end
end

MUSIC_STREAMS[st_type][st_name] = {
    stream_volume = 0,
    volume_type = vol_type,
    stream_sleeping = true,
    playback_responce = false,
    current_sound = NewSound,
    sound_num = 1,
    stream_list = st_list,
}

end

local function StreamNextMusic(st) st.playback_responce = false

if st.sound_num < #st.stream_list then
    st.sound_num = st.sound_num + 1
else
    st.sound_num = 1
end
local next_music = st.stream_list[st.sound_num]
if #st.stream_list > 1 then
    if st.sound_num + 1 <= #st.stream_list then
        content_provider:Preload(st.stream_list[st.sound_num + 1])
    else
        content_provider:Preload(st.stream_list[1])
    end
end

local OldSound = st.current_sound

local NewSound = Instance.new("Sound")
NewSound.Parent = script
NewSound.Name = OldSound.Name
NewSound.SoundId = next_music
NewSound.Volume = OldSound.Volume

OldSound.Name = "OLD_" .. OldSound.Name
coroutine.resume(coroutine.create(function()
    OldSound:Stop()
    wait(0.5)
    OldSound:destroy()
end))

st.current_sound = NewSound
NewSound:Play()

end

local function RemoveStream(st) coroutine.resume(coroutine.create(function() local last_tick = tick() while st.stream_volume > 0 do RenderStepped:wait() local delta = tick() - last_tick last_tick = tick()

        st.stream_volume = math.max(0, st.stream_volume - delta * Settings.VolumeDropRate)
        st.current_sound.Volume = st.stream_volume * st.volume_type
    end
    st.current_sound:Stop()
    wait(0.2)
    st.current_sound:destroy()
end))

end

local function ChangeStreamVolume(st_type, st_name, amm) MUSIC_STREAMS[st_type][st_name].stream_volume = math.max(0, math.min(1, MUSIC_STREAMS[st_type][st_name].stream_volume + amm)) MUSIC_STREAMS[st_type][st_name].current_sound.Volume = MUSIC_STREAMS[st_type][st_name].stream_volume * MUSIC_STREAMS[st_type][st_name].volume_type if amm > 0 and MUSIC_STREAMS[st_type][st_name].stream_sleeping then MUSIC_STREAMS[st_type][st_name].stream_sleeping = false MUSIC_STREAMS[st_type][st_name].current_sound:Play() end end

local function CheckStream(st) if st.stream_sleeping then return end if not st.playback_responce then if st.current_sound.TimePosition > 0 then st.playback_responce = true end elseif st.current_sound.TimePosition == 0 then StreamNextMusic(st) end end

--radio sounds local RadioSoundHolder = camera:FindFirstChild("RadioSoundHolder") if RadioSoundHolder == nil then RadioSoundHolder = Instance.new("Model") RadioSoundHolder.Name = "RadioSoundHolder" RadioSoundHolder.Parent = camera else RadioSoundHolder:ClearAllChildren() end

local function NewSoundSourcePart() local np = Instance.new("Part") np.CanCollide = false; np.Anchored = true np.Size = Vector3.new(0.2, 0.2, 0.2) np.Transparency = 1; np.TopSurface = 0; np.BottomSurface = 0 return np end local function ClearRadioSound(snd_obj) snd_obj[2]:Stop() coroutine.resume(coroutine.create(function() wait(2) snd_obj[1]:destroy() end)) end local function GetPlayerPosition(pname) local get_plr = game.Players:FindFirstChild(pname) if get_plr ~= nil then local char = get_plr.Character if char ~= nil then local rp = char:FindFirstChild("HumanoidRootPart") if rp ~= nil then return rp.Position end end end return nil end local function CreateNewRadioSound(s_id) local np = NewSoundSourcePart() np.Parent = RadioSoundHolder local ns = Instance.new("Sound") ns.Volume = Settings.RadioVolume ns.Looped = true if tostring(s_id) ~= nil and s_id ~= 0 then ns.SoundId = "rbxassetid://" .. tostring(s_id) end ns.Parent = np return {np, ns, s_id, false} end local RunningRadioSounds = {} --pname = {part, sound, sound_id, is_running}

--LOBBY MUSIC STREAM CreateStream("Lobby", "StreamMain", Settings.LobbyVolume, ScrambleArray(LOBBY_MUSIC))

-------------------WAITING UNTIL PLAYER LOADS------------------- while true do if CLIENT_DATA["SessionProfile"] ~= nil then if CLIENT_DATA["SessionProfile"]["PlayerLoaded"] == true then break end end wait() end

local last_tick = tick() RenderStepped:connect(function() local delta = tick() - last_tick last_tick = tick()

local is_alive, in_game = GetPlayerStatus()
local is_spectating = (_G.PlayerSpectating == true)
local in_game_streams, stream_type = GetInGameStreams()
local round_end = CheckIfRoundEnd()

--new stream creation & cleaning
for st_nm, st_list in pairs(in_game_streams) do
    if MUSIC_STREAMS.InGame[st_nm] == nil then
        if st_nm == "RoundStart" or st_nm == "RoundEnd" then
            CreateStream("InGame", st_nm, Settings.RoundStartEndVolume, st_list)
        else
            CreateStream("InGame", st_nm, Settings.GameVolume, st_list)
        end
    end
end
for st_nm, st_obj in pairs(MUSIC_STREAMS.InGame) do
    if in_game_streams[st_nm] == nil then
        RemoveStream(st_obj)
        MUSIC_STREAMS.InGame[st_nm] = nil
    end
end

--volume control
local in_game_streams_on = (is_alive or in_game or is_spectating or round_end)

if _G.NoMusicStream then
    ChangeStreamVolume("Lobby", "StreamMain", -delta * Settings.VolumeDropRate)
    for st_nm, _ in pairs(MUSIC_STREAMS.InGame) do
        ChangeStreamVolume("InGame", st_nm, -delta * Settings.VolumeDropRate)
    end
elseif in_game_streams_on then
    ChangeStreamVolume("Lobby", "StreamMain", -delta * Settings.VolumeDropRate)
    for st_nm, _ in pairs(MUSIC_STREAMS.InGame) do
        if st_nm == stream_type then
            ChangeStreamVolume("InGame", st_nm, delta * Settings.VolumeRaiseRate)
        else
            ChangeStreamVolume("InGame", st_nm, -delta * Settings.VolumeDropRate)
        end
    end
else
    ChangeStreamVolume("Lobby", "StreamMain", delta * Settings.VolumeRaiseRate)
    for st_nm, _ in pairs(MUSIC_STREAMS.InGame) do
        ChangeStreamVolume("InGame", st_nm, -delta * Settings.VolumeDropRate)
    end
end

--music switching
for _, st_type in pairs(MUSIC_STREAMS) do
    for _, st_obj in pairs(st_type) do
        CheckStream(st_obj)
    end
end

--radio sounds
local radio_snds = CLIENT_DATA.GetRadioSounds() --player = {sound_id, is_playing}
--sound cleanup
for pnm, snd_dat in pairs(RunningRadioSounds) do
    if radio_snds[pnm] == nil then
        ClearRadioSound(snd_dat)
        RunningRadioSounds[pnm] = nil
    else
        if radio_snds[pnm][1] ~= snd_dat[3] then
            ClearRadioSound(snd_dat)
            RunningRadioSounds[pnm] = nil
        end
    end
end
--RunningRadioSounds = {} --pname = {part, sound, sound_id, is_running}
--sound updating
for pnm, snd_inf in pairs(radio_snds) do
    if RunningRadioSounds[pnm] ~= nil then
        if RunningRadioSounds[pnm][4] and not snd_inf[2] then
            RunningRadioSounds[pnm][2]:Stop()
            RunningRadioSounds[pnm][4] = false
        elseif not RunningRadioSounds[pnm][4] and snd_inf[2] then
            RunningRadioSounds[pnm][2]:Play()
            RunningRadioSounds[pnm][4] = true
        end
        local get_ppos = GetPlayerPosition(pnm)
        if get_ppos ~= nil then
            RunningRadioSounds[pnm][1].CFrame = CFrame.new(get_ppos)
        end
        if not _G.NoMusicStream and (in_game or is_spectating) then
            RunningRadioSounds[pnm][2].Volume = Settings.RadioVolume
        else
            RunningRadioSounds[pnm][2].Volume = 0
        end
    else
        local initial_pos = GetPlayerPosition(pnm)
        if initial_pos ~= nil then
            RunningRadioSounds[pnm] = CreateNewRadioSound(snd_inf[1])
            RunningRadioSounds[pnm][4] = snd_inf[2]
            if snd_inf[2] then
                RunningRadioSounds[pnm][2]:Play()
            end
            RunningRadioSounds[pnm][1].CFrame = CFrame.new(initial_pos)
        end
    end
end

end)~~~~~~~~~~~~~~~~~


~~~~~~~~~~~~~~~~~

0
Click the Lua symbol to format your code in code blocks. mattscy 3725 — 6y
0
you also have to use RemoteEvents to change things in Workspace when FE is on. NsNidPL 41 — 6y

Answer this question