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

Value Name script doesn't work?

I'm creating a script that makes a value for each specific player when they join the game.

(I've tried to use plr and it hasent worked)

function onPlayerAdded(plr)
	local plruser = plr
	defaultvalue = script.Default
	
	mv = defaultvalue:Clone()
	mv.Name = ""..plruser
	mv.Value = 999
end

game.Players.PlayerAdded:connect(onPlayerAdded)

Error: Workspace.Script:8: attempt to concatenate local 'plruser' (a userdata value)

1 answer

✓ Accepted answer

you are trying to assign the name to the player object ,Lua_errors

Some of the problems

function onPlayerAdded(plr)
    local plruser = plr -- you have the variable plr so you don't need another one
    defaultvalue = script.Default -- if you are only using this once then you do not need to create a variable

	-- you make a clone but do not set its parent so it will be removed after the code block ends
    mv = defaultvalue:Clone() 

   -- never use implicitly conversions as they are very bad practice as you have no control over how this is done
    mv.Name = ""..plruser -- since plruser  is the player object it cannot be converted  this way
    mv.Value = 999
end

game.Players.PlayerAdded:connect(onPlayerAdded)

The Solution:-

function onPlayerAdded(plr)
	local mv = script.Default:Clone() -- I would use server storage but I don't know why you need this done this way
	mv.Name = plr.Name -- the name of the player
	mv.Value = 999
	mv.Parent = -- some parent 
end

game.Players.PlayerAdded:connect(onPlayerAdded)

Hope this helps

1 comment

0

Thanks!

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