How to Display Text on Screen Programmatically in Roblox

I’m currently working on building my first game in Roblox, and I need to be able to print out some information to the screen for debugging. Normally you can just use “print()” to display text for debugging / texting purposes, but I’ve noticed that this doesn’t work when you’re testing multiplayer functionality. Right now I’m trying to detect collisions between Humanoids, and print just isn’t working for me in this specific circumstance since I have to run the game in multiplayer mode (print works fine for me when just running the game as a single player however).

Okay so let’s get to it, how to display text on screen programmatically in Roblox. First you’ll need to add ScreenGui to the StarterGui in Roblox Studio. If you need help with this, reference this tutorial from Roblox on how to add a scoreboard: https://create.roblox.com/docs/tutorials/building/ui/creating-a-score-bar

Then you’ll want to add a TextLabel to your ScreenGui, and after that, add a ModuleScript called DisplayTextModuleScript.

Then under ServerScriptServer, add another script called PrintToOnScreenLogger.

Here is a screenshot of what this initial setup should look like in Roblox Studio:

local module = {}
function Display(text)
local textLabel = script.Parent
textLabel.Text = text
end
module.Display = Display
return module
local DisplayTextModule = require(script.Parent.Parent.StarterGui.ScreenGui.OnScreenLogger.TextLabel.DisplayTextModuleScript)
DisplayTextModule.Display("hello, world")

The finished product will look like:

 

topherPedersen