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

OnServer Event attempt to concatenate local what?

Asked by 4 years ago

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

Log in to vote
1
Answered by
cegberry 432 Moderation Voter
4 years ago
Edited 4 years ago

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)

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. Cryo_Dev 9 — 4y
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. Cryo_Dev 9 — 4y
0
Okay cegberry 432 — 4y
Ad

Answer this question