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

Attempt to concatenate string with userdata?

Client

MusicFrame.RemoteEvent:FireServer(SongIdTextBox.Text) -- I put 142376088 (its raining tacos)

server

wait(2)
local Sound = workspace.Sound
script.Parent.OnServerEvent:Connect(function(id)
	Sound.SoundId = "http://www.roblox.com/asset/?id="..id
end)

any ideas?

1 comment

0

I also tired rbxassetid://.

2 answers

✓ Accepted answer

The first argument received by the .OnServerEvent signal is the Client firing the Remote (it's Player Object; a userdata). Since we don't need to use it, we'll just put it off under _. With that aside, all trailing arguments will follow respectively:

local Sound = workspace.Sound
script.Parent.OnServerEvent:Connect(function(_, id)
    Sound.SoundId = "rbxassetid://"..id
end)

It's also best that you use tonumber() when reading for an Asset Id, as to ensure there are no affiliate characters aside from numerical. If you want to go a little further, you can use a String Pattern to dissect an Asset Id from any alphanumeric string literal: str:match("[%d]+"). This way, we minimize the possibility of load errors.

1 comment

0

Omg, yeah I forgot. Thanks I made a beginner mistake lol!

the first parameter of an OnServerEvent connection will always be the player who fired that RemoteEvent

so, if you sent the server "foo" and "bar" on the client, the server would get the player who fired the event, "foo", and "bar"

--localscript
local RemoteEvent = path.to.RemoteEvent

RemoteEvent:FireServer("foo", "bar")

-- script
local RemoteEvent = path.to.RemoteEvent

RemoteEvent.OnServerEvent:Connect(function(arg1, arg2, arg3)
	print(arg1, arg2, arg3) --> [your username here], "foo", "bar"
end)

to fix your problem all you have to do is add a player parameter

wait(2)
local Sound = workspace.Sound
script.Parent.OnServerEvent:Connect(function(player, id)
    Sound.SoundId = "http://www.roblox.com/asset/?id="..id
end)

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