Why is this not working?

Hi, i can’t figure out why this is not working. This is in a localscript.

local Frame = script.Parent.Frame
local Username = Frame.Username.Username
local Wachtwoord = Frame.Wachtwoord.Wachtwoord
local Inloggen = Frame.Inloggen
local Help = Frame.Help

local Groep = 5348676
local Rank = 9

Inloggen.MouseButton1Click:Connect(function(plr)
	print(plr.Name) --only "plr" is also not working, in the output it says "nil"
end)

try using WaitForChild(), the ui elements probably haven’t loaded in yet.

In the output it says:

Players.DefaultSources.PlayerGui.ScreenGui.InlogFrame.Handler:11: attempt to index nil with 'Name'

Why do you take the player out of the button? You should use local scripts in order to contact gui elements. Therefore, to find out the player’s name you need to:

local Frame = script.Parent.Frame
local Username = Frame.Username.Username
local Wachtwoord = Frame.Wachtwoord.Wachtwoord
local Inloggen = Frame.Inloggen
local Help = Frame.Help

local player = game:GetService("Players").LocalPlayer

local Groep = 5348676
local Rank = 9

Inloggen.MouseButton1Click:Connect(function()
	print(player.Name)
end)
1 Like

I dont think that

returns the player, your going to need to get the player like this

local plr = game.Players.LocalPlayer
1 Like

Alright, thank you. It’s working now!

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