hello!
i want to make a text box gui where if i type someones nickname, he gets awarded a badge. i tried to get user id by username, but it doesnt work. i didnt find the solution anywhere. dev console says: “Players:GetUserIdFromNameAsync() failed: Unknown user”. here is my script in ServerScriptService:
local FunnyBadgeID = 2124770603
local FunnyPlayerUsername = game.StarterGui.FunnyBadgeGiver.Frame.TextBox.Text
local FunnyPlayerID = game.Players:GetUserIdFromNameAsync(FunnyPlayerUsername)
game:GetService("BadgeService"):AwardBadge(FunnyPlayerID, FunnyBadgeID)
If you are testing it on studio, it would likely to error since your UserId ranges from 0 and below on studio testing. You should try testing it by publishing and joining the game.
Try printing FunnyPlayerUsername and see what’s being printed. If it prints out something other than username, you should provide the full code including part that sets text to the username or whatsoever
do i put local gui = game.Players.LocalPlayer:WaitForChild('UI') inside the local script in screen gui? also, how do i use remotes since im not really good at studio?
Yes, but change the UI part with your text box. To use remotes, place a RemoteEvent in ReplicatedStorage, then follow the example:
-- server
local repl = game:GetService("ReplicatedStorage")
local rem = repl:WaitForChild("Remote")
rem.OnServerEvent:Connect(function(player, data)
print(player.Name, data)
end)
-- client
local repl = game:GetService("ReplicatedStorage")
local rem = repl:WaitForChild("Remote")
-- "data" is the data you want to send, this is only an example
local data = "abc"
rem:FireServer(data)
The example prints your username, then “abc” when the localscript fires the remote. The player part in the server is the player object of the player that fired the remote. The remote can have any name, just make sure to edit the example accordingly.
-- client
local repl = game:GetService("ReplicatedStorage")
local rem = repl:WaitForChild("Remote")
-- "data" is the data you want to send, this is only an example
local data = "abc"
rem:FireServer(data)