How to grab a playersname with an object (Read post)

So I have this bike game, and I need to find the player bike because im working on a bike shop, and the bike is named “PlayersBike” player of course being the player name, how would I find this using the player?

If you mean that you have a Player object, and you want to find the Bike in Workspace, then you could do something like this:

local Player = game.Players.Pooglies
local Bike = game.Workspace:FindFirstChild(Player.Name .. "sBike")

@BreadyToCrumble’s method would work. You could also create a objectvalue somewhere in the player(or anywhere you want to store it) with the value being the Player’s bike. You would always have access to it by just doing
local plrBike = game.Players:FindFirstChild(“Player”):FindFirstChild(“Bike”).Value
something like that atleast :slight_smile:

@BreadyToCrumble I think you misunderstand the post - OP wants to grab the player’s name from an object, not vice versa. This solution wouldn’t be appropriate. The solution @SkoobiDoobiDoo posted is more accurate to the inquiry this thread poses.

On the other hand, I’ve got my own to share. If the name of an object is hard coded like that, as in [x]sBike, you can sub out that part to get the player’s name. This is an example of the paradigm you can approach the problem with, not a concrete piece of code to work from.

-- sBike is 5 characters
local objectSuffix = "sBike"
local playerName = object.Name:sub(1, object.Name:len() - objectSuffix:len())
print(playerName)

I think his title contradicts the post. The title is asking to find the name, while his post is asking to find the bike. Whatever it is, he’s now got solutions to either problem. I’d call it a success!

this is how it is setup. (On the right) how do I find the PoogliesCharacter

1 Like

Same way as getting the bike with a minor edit.

local objectSuffix = "Character" — assuming you do not automatically add an “s” as there is an “s” in your name.
local playerChar= object.Name:sub(1, object.Name:len() - objectSuffix:len())
print(playerChar)

Wont let me do - - cause im on ios, but thats supposed to be a comment.

But is says object.Name but I have nothing with object.

Object is the path to the object. ex Lighting is game.Lighting.