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

OnServer Event attempt to concatenate local what?

I'm working on a Command which plays music globally and Roblox keeps outputting this following output.

ServerScriptService.EventFunctions:72: attempt to concatenate local 'AudioId' (a userdata value)

the code is as follows:

On Server Script

--// Local Variables
local PlayMusicEvent = game:GetService("ReplicatedStorage"):WaitForChild("PlayMusic")

--// OnServerEvent
PlayMusicEvent.OnServerEvent:Connect(function(AudioId)
	
	local S = Instance.new("Sound")
	S.Playing = true
	S.Volume = 1
	S.SoundId = "rbxassetid://" .. AudioId
	S.Name = "AddedMusic"
	S.Parent = game.Workspace
	
end)

On Client LocalScript

--// Local Variables
local Event = game:GetService("ReplicatedStorage"):WaitForChild("PlayMusic")
local AudioIDField = script.Parent.Parent.MusicIdFieldFrame.MusicIdField

--// FireServer
game.ReplicatedStorage.PlayMusic:FireServer(AudioIDField.Text)

I haven't a clue why it keeps saying that local 'AudioId' is a userdata value whenever the Event is fired is a really straight forward script pass the ID to the server to then create the Sound Object and put the SoundId the user picked. Can anyone else spot why this happens?

1 answer

✓ Accepted answer

By default the 1st parameter is the Player object who fired the remote, this means the script thinks AudioId is the player, try adding another parameter before AudioId to specify the player:

PlayMusicEvent.OnServerEvent:Connect(function(Player, AudioId)

3 comments

0

But I haven't given it a pass through of "Player" only the SoundId I've managed to do it with a Time Event for another command which doesn't give this problem.

0

Okay I did it and it worked thank you, I find it stupid that in some instances the default 1st is Player and in some it isn't very confusing, now it works now thanks.

0

Okay

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