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

Need help with "attempt to concatenate string with userdata" in script?

Hi! I've got a quite advanced ban-system script. But, however my medium-script skillz. I can't fix my problem.

I get this error-output:

Players.HeadlessDeathSpeaker.PlayerGui.BanList.BanList.HeadlessDeathSpeaker.BanlistCoreScript:44: attempt to concatenate string with userdata

This is a bit of the script:

DeReden = script.Parent.DeReden
BanDate = script.Parent.Date.Value
BanNote = script.Parent.Parent[PlayerName].BanAppeal
BanStat = script.Parent.BanStatus.Value
local Speler = script.Parent.Parent.Parent.Parent.Parent
local PlayerName = Speler.Name

Speler:Kick('Dear '..PlayerName..'You have been banned since '..BanDate..' for '..DeReden..'. The owner left you a note: "'..BanNote..'". Cya!')

Speler = Player (current player)

The error does NOT appear if i remove "..DeReden.." and "..BanNote.."

Both are a BoolValue in the script. Also, ..BanDate.. is StringValue.

Why won't BoolValue work, and BanDate does?

This script is inside a PlayerGui

2 comments

0

DeReden is a userdata, assuming its some type of value, simply add .Value to the end

0

Yep, you right! My bad. I thought i added .Value to it, as that makes sence yeah xD

1 answer

Given that they are instances (which are userdata by roblox) and not userdata you created yourself using newproxy(true), you can simply add tostring() around the name of the userdata.

This will invoke the __tostring metamethod of the userdata (which all Roblox instances already have set to their ClassName. In the case that it's custom userdata that you made, you'll have to add a function for __tostring yourself:

local module = newproxy(true)
local metatable = getmetatable(module)

metatable.__tostring = function(self)
	-- return the value you want printed.
end

-- rest of your stuff

return module

And then call tostring() on it like normal

Remember, only use that if you made the userdata yourself, otherwise, just add tostring() around the name, and that returns the ClassName of the instance.

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