I don't know how get the player information

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

  1. What do you want to achieve? I want to make if the Player click the button, called claim (script.Parent), it will print his name, and show the username on a textlabel on a screen.

  2. What is the issue? I tried a lot of ways, to get it (Remote events) and ecc.

  3. What solutions have you tried so far? I tried to use the PlayerAdded function, but it doesn’t work, and if I don’t use it, the console print: name is nil (player.Name).

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!

script.Parent.MouseButton1Click:Connect(function(player)

local OrderNumber = script.Parent.Parent.Name
		

				local order = script.Parent.Parent
				if order.Claimed.Visible == true then return end
				
		script.Parent.Text = "Complete"
				local claim = Instance.new("BoolValue")
				claim.Name = "hasClaimedOrder"
				claim.Parent = player
				
				order.Claimed.Visible = true
			
				order.claimeduser.Text = "Claimed by: " .. player.Name  -- error "name is nil"
		order.Claimed.UserWhoClaimed.Value = player.Name -- error "name is nil"
				script.Parent.check.Value = false

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.

1 Like
if script:IsA("Script") then script.RunContext = Enum.RunContext.Client end
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
    local OrderNumber = script.Parent.Parent.Name
	local order = script.Parent.Parent
	if order.Claimed.Visible then return end
				
	script.Parent.Text = "Complete"

	local claim = Instance.new("BoolValue")
	claim.Name = "hasClaimedOrder"
	claim.Parent = player
				
	order.Claimed.Visible = true
			
	order.claimeduser.Text = `Claimed by: {player.Name}`  -- error "name is nil"
	order.Claimed.UserWhoClaimed.Value = player.Name -- error "name is nil"
	script.Parent.check.Value = false
end)
1 Like

Alright, let me try in a local script.

Yeah, the thing is: .MouseButton1Click does not return any parameters meaning player was nil. But now you would want to run the non-gui code through the server using a RemoteEvent.

1 Like

Even the Remote Event doesn’t work…

Local Script 

local plr = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
	
	game.ReplicatedStorage.McOrderSystem["Getting info"]:FireServer(plr)
end)

Script
game.ReplicatedStorage.McOrderSystem.namegett.OnServerEvent:Connect(function(plr)
	print(plr.Name)
end)

And of course in the console there are 0 errors.
Location of files: local script is parent of the button
script: ServerScriptService.

The LocalScript should be a child of the button. And also, you didn’t connect to the same event.

image
ignore ordercommands

1 Like

They aren’t the same event. You need to make them connect to the same one.

1 Like

right, i didnt see it.
how dumb i am…

I changed the replicated storage name, and it’s still not working.

local plr = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
	
	game.ReplicatedStorage.McOrderSystem.namegett:FireServer(plr)
end)
game.ReplicatedStorage.McOrderSystem.namegett.OnServerEvent:Connect(function(plr)
	print(plr.Name)
end)

Confirm the GUI is a descendant of StarterGui?

It’s a surface gui, located in Workspace.

LocalScripts don’t run in Workspace. Try putting the SurfaceGui in StarterGui and set the Adornee property to the part.

1 Like

Thank you very much! So sorry for the errors, as I’m a learning scripting from 1.5 year. Have a nice day.

No worries! I’ve also only been scripting for about 1.833 years.

1 Like

Uh? Are you sure about that? I’ve left a LocalScript in a folder of mine in the workspace for a small shop system and it been working just fine. Unless there’s some really specific things related to that that I dont know about since I’ve basically just started

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.