Index with Name

Quite simple, this script doesn’t print the players name

local groupid = nil -- For now at least xD
local allowedRank = 1 

function onClicked(plr)
	print(plr.Name .. "Has clicked!" )
	local rank = plr:GetRankInGroup(groupid)

	if rank < allowedRank then
		return
	end
end

script.Parent.MouseButton1Click:Connect(onClicked)

Done some research same issue, unless I wrote something wrong, not sure… thoughts?

MouseButton1Click doesn’t pass a player object.

Is it a server script?

[Some characters to fill the blank]

1 Like

Yep! It is a server script, on the thing, I tried using local but it didn’t do anything.

Oh alright, should I just use click detectors instead of that?

Isn’t that more convenient anyway? Or was a specific reason for why you went with this approach?

As someone already pointed out, MouseButton1Click doesn’t pass the player object. However, to access the player’s StarterGui from a server script, you need to have that specific player in some variable already anyways, so you could use that in your code to get the group rank.

TextButtons seem to be more faster than clickdetectors when trying them, either that or my client was just acting slow.

if this is inside an UI you should be using a localscript, and then you can get the player like so

local Players = game:GetService("Players")
local Player = game.Players.LocalPlayer
local groupid = 1

function onClicked()
	print(Player.Name .. "Has clicked!" )
	local rank = Player:GetRankInGroup(groupid)
end

script.Parent.MouseButton1Click:Connect(onClicked)

if this is inside a ClickDetector then you can pass the player as the argument

local groupid = 1
function onClicked(Player)
	print(Player.Name .. "Has clicked!" )
	local rank = Player:GetRankInGroup(groupid)
end

script.Parent.MouseClick:Connect(onClicked)