Hi! I'm new here and new to programming in general. I'm having an issue getting a client-side GUI to display the contents of a Role.txt file located in garrysmod/data. This code is located in addons/myaddon/lua/autorun/client/classesgui.lua. When this is ran, why does it return an error "bad argument #1 to 'SetText' (string expected, got no value)?
local frame = vgui.Create("DFrame")
frame:SetSize(500,500)
frame:SetVisible(true)
frame:MakePopup()
local label = vgui.Create("DLabel" , frame)
label:SetPos(0,0)
label:SetSize(1000,720)
label:SetVisible(true)
label:SetText(file.Read("Role.txt", "DATA"))
Because your Role.txt I certain is on serverside. They can't see that file. You can send a content of it by networking or just:
local Role = "content of Role.txt"
Reference for networking here:
Category:Net
Net Library Usage
Net Library Example
Thanks! I have it working now, huge thanks for your support.
I'm having a problem - when trying to give out classes to a particular player (directly sending a table instead of giving the contents of a .txt file), the player simply does not recieve the broadcast. I'm not getting any error messages - the message simply won't be received.
Segment of server-side script:
function AddClass(ply)
local FirstClass = MakePlayerClass()
FirstClass.Owner = ply:SteamID():gsub(":","_") --You can't write files with the characters : and _
FirstClass.Name = ply:Name()
SaveClass(FirstClass, ply)
util.AddNetworkString("SendClass")
net.Start("SendClass")
net.WriteTable(FirstClass)
net.Send(ply)
end
hook.Add( "PlayerInitialSpawn", "AddPlayerClass", AddClass )
Client side receiver:
print("Script started")
net.Receive ("SendClass", function ()
RecievedClass = net.ReadTable()
print (RecievedClass.Armor)
print(net.ReadString())
print("Message recieved")
end )
Result: Only "Script started" is printed to the client's console. Without errors I can't figure out why the client is no longer receiving messages!
Do not `util.AddNetworkString` more than once.
You're writing a table and reading table and the string. No string were written
Removing the "net.ReadString" produces the same result. "util.AddNetworkString" can only be found once in both scripts in entirety.
When I went on both scripts and removed everything else to make sure the script is even sending a message, the same result happened - only "Script Started" was printed. This lets me know that the client isn't getting the Receive, and I have no idea why. I hope I'm not being too much of a burden, I'm new to this and I'm trying to learn this.
function AddClass(ply)
local FirstClass = MakePlayerClass()
FirstClass.Owner = ply:SteamID():gsub(":","_") --You can't write files with the characters : and _
FirstClass.Name = ply:Name()
SaveClass(FirstClass, ply)
util.AddNetworkString("SendClass")
net.Start("SendClass")
net.Send(ply)
end
hook.Add( "PlayerInitialSpawn", "AddPlayerClass", AddClass )
print("Script started")
net.Receive ("SendClass", function ()
print("Message recieved")
end )
Your "AddNetworkString" is in hook. It will call it as many times as players join
Your util.AddNetworkString should be ran outside of any hooks (everyone usually just puts them at the very top of the file.)
Other than that this all seems fine. Retest with the util.AddNetworkString fixed. I'd reccomend also doing what @Spar said and adding a print message inside the serverside hook to check it is running.
Sorry, you need to Log In to post a reply to this thread.