dev console still gives an error “Players:GetUserIdFromNameAsync() failed: Unknown user”
Please show us the scripts and the explorer tree.
here is my entire script inside server script service
local FunnyBadgeID = 2124770603
local FunnyPlayerUsername = game.StarterGui.FunnyBadgeGiver.Frame.TextBox.Text
local FunnyPlayerID = game.Players:GetUserIdFromNameAsync(FunnyPlayerUsername)
local data = FunnyPlayerUsername
local repl = game:GetService("ReplicatedStorage")
local rem = repl:WaitForChild("Remote")
local gui = game.Players.LocalPlayer:WaitForChild("Remote")
game:GetService("BadgeService"):AwardBadge(FunnyPlayerID, FunnyBadgeID)
rem:FireServer(data)
am i doing it right?
Put the localscript part of the example in your GUI, like this example from a game I’m making:
This is only an example, you don’t have to put in all of the other things I added. In this script, you need to put local gui = game.Players.LocalPlayer:WaitForChild('UI')
, then send the textbox data over the remote. The script in ServerScriptService should handle giving the badge.
my server script service
my starter gui:
local script inside screen gui:
if game.Players.LocalPlayer.Name == "Dude8248" then --put in ur username
script.Parent.Enabled = true
else
script.Parent.Enabled = false
end
do i create a completely new local script inside screen gui and put everything from script in server script service in it?
The waitforchild part isn’t required when the script is under the GUI itself.
-- client
local repl = game:GetService("ReplicatedStorage")
local rem = repl:WaitForChild("Remote")
local data = script.Parent.Frame.TextBox.Text
local function fire(x) -- this is here so you can use a button for example
rem:FireServer(x)
end
sorry for the late reply, but my dev console still says “unknown user”
can you please tell me if im doing something wrong?
here is my server script service:
FunnyBadgeGiver script inside of it:
local FunnyBadgeID = 2124770603
local FunnyPlayerUsername = game.StarterGui.FunnyBadgeGiver.Frame.TextBox.Text
local FunnyPlayerID = game.Players:GetUserIdFromNameAsync(FunnyPlayerUsername)
local data = game.StarterGui.FunnyBadgeGiver.Frame.TextBox.Text
local repl = game:GetService("ReplicatedStorage")
local rem = repl:WaitForChild("Remote")
local gui = game.Players.LocalPlayer:WaitForChild("Remote")
game:GetService("BadgeService"):AwardBadge(FunnyPlayerID, FunnyBadgeID)
local data = game.StarterGui.FunnyBadgeGiver.Frame.TextBox.Text
local function fire(Remote)
rem:FireServer(Remote)
end
my starter gui:
local script inside of it is so the badge giving gui is only visible to me
and i also have remote event inside of replicated storage called “Remote”
This can only be ran from the client. Attempting to do so from the server will yield no results, or an error. You can only Fire the server from local scripts. Also your server script never picks up the event once fired.
So basically:
local rem = repl:WaitForChild("Remote")
rem.OnServerEvent:Connect(function(player, data) -- data is the name of the user
local FoundPlayer = game.Players:GetPlayerFromCharacter(workspace[data])
-- Promptly award the user you fired from the TextBox GUI
game:GetService("BadgeService"):AwardBadge(FoundPlayer.UserId, FunnyBadgeID)
end)
Also why are you using StarterGui
from the server? That’s the default GUI section that copies the actual GUI to the players PlayerGui
. You need to get the actual PlayerGui
folder inside the player object, but you shouldn’t even be doing this from the server because the client should be in charge of these variables because the input is done on the client. The entire system is pretty much faulty at this point from what I can see.
-- Local script would handle these
local data = game.StarterGui.FunnyBadgeGiver.Frame.TextBox.Text
local gui = game.Players.LocalPlayer:WaitForChild("Remote")
do i put the thing above in the same local script as this?
local rem = repl:WaitForChild("Remote")
rem.OnServerEvent:Connect(function(player, data) -- data is the name of the user
local FoundPlayer = game.Players:GetPlayerFromCharacter(workspace[data])
-- Promptly award the user you fired from the TextBox GUI
game:GetService("BadgeService"):AwardBadge(FoundPlayer.UserId, FunnyBadgeID)
end)
Okay, well the entire way you’ve done it is a little too wrong to a little bit of fixes here and there, and you might have to rewrite the entire thing. You can use what I wrote below as an example.
Let’s pretend I’m making a Money system where only admins can give money to themselves. (You could make it so that it goes off Player name and gives money to any player but for the sake of simplicity, I left that out) Here’s how you would do that:
-- LOCAL SCRIPT BELOW THIS --
-- Reference the GUI objects that I will be using to fire the server, mainly the button
Button = script.Parent.
TextBox = script.Parent.Parent:WaitForChild("TextBox") -- location and name of your text box
-- Get the RemoteEvent from ReplicatedStorage
local Remote = game:GetService("ReplicatedStorage").RemoteEventName -- enter the name of your remote event here
-- add a debounce so the button cannot be fired too many times
local db = false
-- Get the button clicked event
Button.MouseButton1Click:Connect(function()
if not db then
db = true
local TextBoxContents = tonumber(TextBox.Text) -- Get my number from the textbox then convert it from a string to a number so we can add it later through server
Remote:FireServer(TextBoxContents)
task.wait(3)
db = false
end
end)
-- SERVER SCRIPT BELOW THIS --
-- Now that we're on the server side, we create our OnServerEvent function, but we first want to make a table of the allowed users to use this feature
local AdminsAllowed = {70489502, 0, 0} -- I usually do this by UserId. Replace the 0s if you have more people that happen to be the admin for the game. In my case, I'm leaving my UserId there.
-- You want to get the same RemoteEvent that client used as well
local Remote = game:GetService("ReplicatedStorage").RemoteEventName -- enter the name of your remote event here
Remote.OnServerEvent:Connect(function(Player, TextBoxContents) -- Since we fired the server, we want to pass through the TextBoxContents variable, and use Player to get the player who fired
if table.find(AdminsAllowed, Player.UserId) then
-- Get the leaderstat that you use to have money changed. In your case, instead of Money, it would look for the player you put in the textbox, and will award the badge here.
local LeaderstatsValue = Player:WaitForChild("leaderstats").Money
LeaderstatsValue.Value = LeaderstatsValue.Value + TextBoxContents -- This will add the TextBox input onto the leaderstats since it was converted to a number client sided
else
Player:Kick("You do not have explicit permission to fire this remote. You have been kicked due to suspicious activity.")
end
end)
ok i changed the scripts a bit and here is what i have:
local script inside the screen gui:
local Button = game.StarterGui.FunnyBadgeGiver.Frame.TextBox
local TextBox = game.StarterGui.FunnyBadgeGiver.Frame:WaitForChild("TextBox")
local Remote = game:GetService("ReplicatedStorage").FunnyRemoteEvent
local db = false
Button.FocusLost:Connect(function()
if not db then
db = true
local TextBoxContents = (TextBox.Text)
Remote:FireServer(TextBoxContents)
task.wait(3)
db = false
end
end)
script inside server script service:
local AdminsAllowed = {651018995}
local FunnyBadgeID = 2124770603
local Remote = game:GetService("ReplicatedStorage").FunnyRemoteEvent
Remote.OnServerEvent:Connect(function(Player, TextBoxContents)
if table.find(AdminsAllowed, Player.UserId) then
game:GetService("BadgeService"):AwardBadge(TextBoxContents, FunnyBadgeID)
else
Player:Kick("no")
end
end)
when i try using it dev console says nothing, but the badge is still not being awarded
This is your issue. You’re not parenting to it. You’re getting the source copy. Change it to something like this:
local Button = script.Parent
because you’re supposed to put the local script as a child of the button
Also why FocusLost? Just make it MouseButton1Click so when you click the button it’ll fire the server.
FocusLost because its a screen gui
ok i changed things that you mentioned and now dev console gives me an error: “MouseButton1Click is not a valid member of ScreenGui “Players.Dude8248.PlayerGui.FunnyBadgeGiver””
FocusLost gives me the same error
Indeed, MouseButton1Click is not an event for a ScreenGui, as you can’t click on something that is simply used for containing Gui elements. The problem here is that Button
is not actually referencing the button you click, but the ScreenGui itself. How to solve is is by referencing the button correctly.
Button = --fix it so it refers to button instead of ScreenGui
ok i created a text button and refered it as a button
it sitll doesnt work and it doesnt say anything in dev console
Shows us all your scripts again. Maybe some videos and stuff along with it would help solve this issue quicker.
my server script service:
FunnyBadgeGiver script inside of it:
local AdminsAllowed = {651018995}
local FunnyBadgeID = 2124770603
local Remote = game:GetService("ReplicatedStorage").FunnyRemoteEvent
Remote.OnServerEvent:Connect(function(Player, TextBoxContents)
if table.find(AdminsAllowed, Player.UserId) then
game:GetService("BadgeService"):AwardBadge(TextBoxContents, FunnyBadgeID)
else
Player:Kick("no")
end
end)
my starter gui:
FunnyBadgeGiver local script inside of screen gui:
local Button = game.StarterGui.FunnyBadgeGiver.Frame.TextButton
local TextBox = game.StarterGui.FunnyBadgeGiver.Frame:WaitForChild("TextBox")
local Remote = game:GetService("ReplicatedStorage").FunnyRemoteEvent
Button.MouseButton1Click:Connect(function()
local TextBoxContents = (TextBox.Text)
Remote:FireServer(TextBoxContents)
end
DudeOnlyGui local script is so its only visible to me
i also have remote event in replicated storage called “FunnyRemoteEvent”