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

Converting a string to a player object?

Hi.

Im creating a give-script. I get the player name from a command:

local ciplr = string.sub(msg, 10, -4)

Now if i try to clone an object into the Inventory of the player, it says:

OKRPLAY is not a valid Member of Players

im using this code:

local ticket = game.ServerStorage.FirstClass:Clone()
ticket.Parent = game.Players[ciplr].Backpack

Is it possible to convert the string to a player object?

1 answer

✓ Accepted answer

A couple things, if they type the name wrong it will break the code caps and everything, and I'm pretty sure you did the substringing wrong where it should be like:

local ciplr = string.sub(msg, 4)

if you want to get rid of the first 4 characters in the string it should be ^

What you're doing should technically work if you have the right string from string.sub but I don't think its substringing right

3 comments

0

The string is right, i printed it. But i cant find the Player OBJECT, because ciplr is a string.

0

then try game.Players:FindFirstChild(ciplr).Backpack

0

Thank you, my problem was: local ciplr = string.sub(msg, 10, -5) ----- Needed to be -5 instead of -4

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