Trying to use the username instead of User ID

I’m trying to use the players username instead of ID. But I’m struggling to get it working.

Server script:

local Event = game.ReplicatedStorage:WaitForChild("GivePoints")

Event.OnServerEvent:Connect(function(player, amount)
	local give = game.Players:FindFirstChild(player)
	give:WaitForChild("leaderstats").Points.Value += amount
end)

The script that fires the remote event:

local Event = game.ReplicatedStorage:WaitForChild("GivePoints")

script.Parent.MouseButton1Click:Connect(function()
	local player = script.Parent.Parent.TextBox.Text
	local amount = script.Parent.Parent.AmountText.Text
	Event:FireServer(player,amount)
end)

If I use the player ID, it works fine. I’m just wondering how to make it so I can type the username. (So It’s easier.)

If you need any more info just ask…

1 Like

You don’t need to fill out the player

local Event = game.ReplicatedStorage:WaitForChild("GivePoints")

script.Parent.MouseButton1Click:Connect(function()
	local amount = script.Parent.Parent.AmountText.Text
	Event:FireServer(amount)
end)

I wouldn’t recommend giving points through a remte event but it’s your choice

2 Likes

Did you forget that OnServerEvent has a player parameter by default? This should be your server script.

local Event = game.ReplicatedStorage:WaitForChild("GivePoints")

Event.OnServerEvent:Connect(function(firer, player, amount)
	local give = game.Players:FindFirstChild(player)
	give:WaitForChild("leaderstats").Points.Value += amount
end)
2 Likes

Server script:

—Server


local Event = game.ReplicatedStorage:WaitForChild("GivePoints")

Event.OnServerEvent:Connect(function(player,reciever ,amount)
	local give = game.Players:FindFirstChild(reciever)
	give:WaitForChild("leaderstats").Points.Value += amount
end)

2 Likes

You can just use Players:GetUserIdFromNameAsync(Username). It converts the username inputted into the UserId of the user. For more info: Players | Documentation - Roblox Creator Hub

2 Likes

It doesn’t, FireServer passes the player by default. So the first argument of OnServerEvent must be a player.

3 Likes
local Event = game.ReplicatedStorage:WaitForChild("GivePoints")

Event.OnServerEvent:Connect(function(player, target, amount)
	local a = game.Players[target]
	a:WaitForChild("leaderstats").Points.Value += amount
end)

After taking a 2nd look at your code, you should be doing this.
And unless this is an admin panel, don’t pass an “amount” value.

(nvm just don’t pass amount)

2 Likes

Never fire anything to the server with leaderstats thats a easy spoof

2 Likes

Yeah I just realized that she/he was firing amount, You should also use a debounce.

2 Likes

That’s what he’s saying. He is passing the target player (Player, Amount) but not receiving the sending player (Sender, Player, Amount)

3 Likes

Make sure you add sanity checks or exploiters will easily get tons of points.

1 Like

How would you add sanity checks to this.

1 Like

Checking the player who fired the remote.

1 Like

You mean a table containing “admins”?

Yes, if that is your method. Everyone has different permission systems.

1 Like

I have no need in adding checks. There’s always gonna be a mod in game as its for a group role play game. (A Game Show)