Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Remote not sending the value of PlaybackLoudness to the server?

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.

1 comment

0

Is there an error?

1 answer

✓ Accepted answer

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)

1 comment

0

This worked perfectly, I guess I just still lack experience with remote events and will need to catch back up on em.

This discussion is preserved as it was. New answers, comments, and votes are closed.