How can i get players name with ui

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Just wanna get player’s name for my ui
  2. What is the issue? Include screenshots / videos if possible!

    Can’t get players name from ui. I can use ui with my name (BerkeCavdaroglu’s Car) But others can’t use it.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried to look but i couldn’t find. And I am also new to scripting nearly idk anything about lua.I can write this by knowing a little of C#
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
-- This is an example Lua code block

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

2 Likes
local Gui = script.Parent
local Player = Gui.Parent.Parent

You are trying to get the players name from the character, what you need to do is put plr.Parent.Name

Serverscripts does not belong inside GUIs.
Use localscripts instead, as they are meant to handle player input.

Then you can get the player’s name with game:GetService('Players').LocalPlayer.Name.

1 Like

He wants it server-sided apparently.

Cough, RemoteEvent:FireServer()

Make it a local script. You can then say local player = game.Players.LocalPlayer

He doesn’t want it to be fired from a remote event unfortunately, So. from my solution is what he needs

Whilst you should make a system using remote events which would be much more efficient and reliable you could make your script like this:

Please note this will only work if this GUI is in the PlayerGui child of a player object

local db = false

function leftClick()
	
	print("click")
	local plr = script.Parent.Parent.Parent.Parent.Parent --// goes up through the 
    --//hierarchy(filltank/Frame/GiveUI/PlayerGui/Player Object)
	db = true
	workspace[plr.Name.."'s Car"].Fuel.Value = 50
	db = false
	
end

script.Parent.MouseButton1Click:Connect(leftClick)

Whilst this should work it is not reliable and would need constant changes as you edit your game through it’s lifetime if you changed your car system etc

However VERY bad practice. You should not be learning new developers this.

Player input should always be handled by the client-side, and if server-communication is needed, simply hook up a RemoteEvent.

1 Like

I’m sorry, I’m just here to assist others from their problems. I got his point and decides to fix that. I only came here to help not to perform an assertion. My bad :sweat_smile:

1 Like

By the way in Xacima’s solution, BerkeCavdaroglu. You can also use this method If you chose it to run in server, use remote event and to make this function you’ll have to utilize a local script and trigger / fire it inside a localscript.

Can I ask another thing in this thread or do i have to open another?

The solution in this thread is fixed, So. yes new thread.

1 Like