Helps with getting a certain player within workspace

Hello everyone,

I am making a script currently here is my code :

script.Parent.Confirm_Button.MouseButton1Click:Connect(function()
	local StringName = tostring(script.Parent.Username_Change.Text)
	
end)

So, I was wanting too do something like :

game.workspace.StringName.Head 

etc

But it won’t let me do that and I don’t know any other way of doing this any advice or help ?

If the script is a local script. Then just get the character from the player.

local player = game:GetService("Players").LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()

Then do:

local StringName = script.Parent.Username_Change.Text
char.Humanoid.DisplayName = StringName

you could use 1 of 2 ways, get the player directly and get the character from there

game.Players[StringName].Character.Head

or just get the character.

workspace[StringName].Head

To try and get a child using a variable, you need to use brackets.

1 Like

Thank you for that quick reply, this worked well thank you.