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

Converting a string to a player object?

Asked by
OKRPLAY 25
6 years ago

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

Log in to vote
0
Answered by
blowup999 659 Moderation Voter
6 years ago
Edited 6 years ago

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

0
The string is right, i printed it. But i cant find the Player OBJECT, because ciplr is a string. OKRPLAY 25 — 6y
0
then try game.Players:FindFirstChild(ciplr).Backpack blowup999 659 — 6y
0
Thank you, my problem was: local ciplr = string.sub(msg, 10, -5) ----- Needed to be -5 instead of -4 OKRPLAY 25 — 6y
Ad

Answer this question