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

Remote not sending the value of PlaybackLoudness to the server?

Asked by 5 years ago
Edited 5 years ago

I wanted to make one of my old visualizer projects work within FE but obviously due to it being made to be specifically local is hard to do so. I attempted to make a remote event for the client to send the server the Playback Loudness, but even with the remote, it kept returning 0. I know the server cant directly read PlaybackLoudness as audios are client based not server based, but It should be possible to send the PlaybackLoudness value to the server on loop with a remote correct? My attempts failed and kept returning 0 and I really am stuck.

Here is the code I have made so far but doesn't work.

--Local V
while wait() do
    local loudness = script.Parent.SoundPart.Sound.PlaybackLoudness
    print(loudness) -- to make sure it isnt some kind of preload bug
    script.Parent.PBL:FireServer(loudness)
end
-- Server V
local PBLEvent = Instance.new("RemoteEvent", script)
PBLEvent.Name = "PBL"
local PBLoudness = 0

function onPBL(PlaybackLoudness)
    PBLoudness = PlaybackLoudness
    print("Updated value to "..PBLoudness) -- checking if the server updates
end

PBLEvent.OnServerEvent:Connect(onPBL)

I've cut out of course the whole visualizer as it still functioned as intended, the only issue is that Loudness will always return 0.

0
Is there an error? User#24403 69 — 5y

1 answer

Log in to vote
0
Answered by
Azarth 3141 Moderation Voter Community Moderator
5 years ago

The first parameter of the RemoteEvent connection is the player from which FireServer was called. The first parameter should be a variable that references the player, the next can be something else, like your loudness value. You're essentially trying to set loudness to the LocalPlayer right now.

Local

local sp = script.Parent
local SoundPart = script.Parent:WaitForChild("SoundPart")
local pbl = sp:WaitForChild("PBL")
-- Use WaitForChild() on objects that need time to load

while wait(1) do
    local loudness = SoundPart.PlaybackLoudness
    print(loudness) -- to make sure it isnt some kind of preload bug
    pbl:FireServer(loudness)
end

Server


local PBLEvent = Instance.new("RemoteEvent", script) PBLEvent.Name = "PBL" local PBLoudness = 0 function onPBL(player, PlaybackLoudness) PBLoudness = PlaybackLoudness print("Updated value to "..PBLoudness) -- checking if the server updates end PBLEvent.OnServerEvent:Connect(onPBL)
0
This worked perfectly, I guess I just still lack experience with remote events and will need to catch back up on em. Spook_Roku 7 — 5y
Ad

Answer this question