• Error when trying to get Steam Name from Client
    13 replies, posted
Hello, I'm unable to get the player's steam/gamemode name. This is the code I'm trying: if CLIENT then   net.Receive("FactionChooseStart",function()     local currentSteamName = LocalPlayer():Name()     local SteamNameSplit = currentSteamName:gsub("%s+", " ")     local completedSteamName = string.Explode(" ", SteamNameSplit)     local randomID = math.random(1000, 9999) -- MORE CODE AFTER THIS There is more code after that, i'm trying to use the variable "CompletedSteamName[1]" and "currentSteamName" Here's the error I receive: attempt to index global 'currentSteamName' (a nil value) I should mention that i've also used local currentSteamName = LocalPlayer():GetName() local currentSteamName = LocalPlayer():Name() Thanks, I'm hoping that it's an easy fix.
Are you running this serverside or clientside? LocalPlayer() does not exist serverside, you have to use player.GetAll() and loop through the values or select a value by the key.
Tried all of your ideas, didn't work unfortunately, and yes this is all in the CLIENT part of a shared file.
Player/Nick
Yup I tried that, same error.
Maybe post the error?
Can you post the full error along with the full source?
I've managed to "fix" the problem. I have to set the variables in each of my button clicks. e.g. button.DoClick = function()         local currentSteamName = LocalPlayer():Name()         local SteamNameSplit = currentSteamName:gsub("%s+", " ")         local completedSteamName = string.Explode(" ", SteamNameSplit)         local randomID = math.random(1000, 9999)   end Is a little bit annoying as I will now have to do that on every button(?) but at least it works! Thanks for the help guys :)
If you assign a local variable in DoClick() you shouldn't expect to use it outside of that function. If you're using the steam name multiple times I would suggest you assign a variable on the parent panel that the buttons can access.
Thanks, I put it in my parent panel (didn't even think of that). I'm not using math.Rand anywhere which makes it weird, the "randomID" variable that uses math.random has been used before in a serverside script and it works fine.. just doesn't here on the clientside. The number always ends in .00? Could it be something to do with this code: RunConsoleCommand("ulx", "setname", currentSteamName, randomID, completedSteamName[1])
It would be very helpful if you just include the full source
if SERVER then   -- util.AddNetworkString("FactionChoose")   util.AddNetworkString("FactionChooseStart")   hook.Add( "PlayerInitialSpawn", "newPlayer", function( ply, text, public )     -- if(ply:GetUserGroup() == "user") then     if(string.lower(text) == "!test") then       timer.Simple( 1, function()         net.Start("FactionChooseStart")         net.Send(ply)       end)     end   end) end if CLIENT then   surface.CreateFont( "DermaDefaultBold22", {     font = "DermaDefaultBold",     size = 22,     shadow = true,     outline = true,   } )   net.Receive("FactionChooseStart",function()     if(!factionMenuStatus) then       factionMenuStatus = vgui.Create("openFactionMenu")       factionMenuStatus:SetVisible(false)     end     if(factionMenuStatus:IsVisible()) then       factionMenuStatus:SetVisible(false)       gui.EnableScreenClicker(false)     else       factionMenuStatus:SetVisible(true)       gui.EnableScreenClicker(true)     end   end)   local FACTIONPANEL = {     Init = function(factionSelf)   factionSelf:SetSize(800, 400)   factionSelf:Center()   factionSelf:SetVisible(true)       local currentSteamName = LocalPlayer():Name()       local SteamNameSplit = currentSteamName:gsub("%s+", " ")       local completedSteamName = string.Explode(" ", SteamNameSplit)       local randomID = math.random(1000, 9999)   local x, y = factionSelf:GetSize()       local factionBackground = vgui.Create("DPanel", factionSelf)   factionBackground:SetPos(8, 75)   factionBackground:SetSize(x-16, y-83)   factionBackground.Paint = function(self,w,h)   surface.SetDrawColor(91,91,91,100)   surface.DrawRect(0, 0, w, h)   surface.SetDrawColor(0,0,0,255)   surface.DrawOutlinedRect(0, 0, w, h)   end       local natoButton = vgui.Create("DButton", factionBackground)   natoButton:SetFont("DermaDefaultBold21")   natoButton:SetTextColor(Color(255,255,255,255))   natoButton:SetText("NATO")   natoButton:SetSize(360,30)   natoButton:SetPos(20, 20)   natoButton.Paint = function(self,w,h)   surface.SetDrawColor(0, 102, 204, 230)   surface.DrawRect(0, 0, w, h)   surface.SetDrawColor(0, 113, 226, 230)   surface.DrawRect(0, 0, w, 2)   surface.SetDrawColor(0,0,0,255)   surface.DrawOutlinedRect(0, 0, w, h)   end   natoButton.DoClick = function()         RunConsoleCommand("ulx", "setname", currentSteamName, "NATO", randomID, "TRAINEE", completedSteamName[1])   factionMenuStatus:Remove()         factionMenuStatus = vgui.Create("openFactionMenu")         factionMenuStatus:SetVisible(false)         gui.EnableScreenClicker(false)   end       local natoDescBack = vgui.Create("DPanel", factionBackground)       natoDescBack:SetSize(360, 230)       natoDescBack:SetPos(20, 70)       natoDescBack:DockMargin(5, 1, 5, 1)       natoDescBack.Paint = function(self,w,h)         surface.SetDrawColor(141,141,141,200)         surface.DrawRect(0, 0, w, 2)         surface.SetDrawColor(0,0,0,255)         surface.DrawOutlinedRect(0, 0, w, h)       end       local natoDescText = vgui.Create( "RichText", natoDescBack )       natoDescText:Dock( FILL )       natoDescText:DockMargin(5, 3, 5, 3)       natoDescText:SetVerticalScrollbarEnabled( false )       natoDescText:SetText( "TESTING THIS BOX just to see how it all looks" )       function natoDescText:PerformLayout()       natoDescText:SetFontInternal( "DermaDefaultBold22" )       natoDescText:SetFGColor( Color( 255, 255, 255 ) )       end     end,   }   vgui.Register("openFactionMenu", FACTIONPANEL) end
Have you tried printing randomId before running the console command? Not sure how RunConsoleCommand works in regards to variable conversion, I would assume it would just use tostring you can try encasing randomId with tostring() and see if it makes a difference.
That did the job. Thanks again
Sorry, you need to Log In to post a reply to this thread.