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

Value Name script doesn't work?

Asked by 7 years ago

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

Log in to vote
2
Answered by 7 years ago
Edited 7 years ago

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

0
Thanks! Warfaresh0t 414 — 7y
Ad

Answer this question