How to solve UIStroke appearing too big on mobile devices

Hey! So, in Roblox, most of the time, your UIStrokes appear too big on mobile devices. I’ll explain how you can fix that!

For this tutorial you will need:
• UserInputService - service
• TouchEnabled - boolean
• A UIStroke - instance
• StrokeThickness - number

• First things first, insert a local script into your ScreenGui

• Next, we get UserInputService:

local UserInputService = game:GetService("UserInputService")

• To progress, we need to get a boolean called “TouchEnabled” if many of you are familiar with it.

local TouchEnabled = UserInputService.TouchEnabled

We need to get our UIStroke

local myTextLabel = script.Parent
local myUIStroke  = TextLabel.UIStroke

We also need to create a number. Not to be confused with an IntValue.

The difference between a number and an intvalue is very simple:

-- IntValues
local myIntValue = Instance.new("IntValue")
myIntValue.Name = "myIntValue"

myIntValue.Value = 5 -- IntValues, as the name suggests, can only be whole numbers
-- myIntValue.Value = 2.5 (this will print out an error)
print(myIntValue.Value) -- This'll print out 5

-- Numbers

local a = 1.5
local b = 4

local myNumberValue = Instance.new("NumberValue")
myNumberValue.Name = "myNumberValue"

myNumberValue.Value = a + b -- This won't print out an error, because NumberValues can be both whole values and decimals

-- Use both specifically for different types of scenarios

Now, here’s the best part! Let’s use an if statement, time to check if the user is on a mobile device

if TouchEnabled then -- We check if the player is on a mobile device (this is also the same as saying if true then or if false then, because "TouchEnabled" is a boolean, and it depends on what device someone is playing on

end
-- Here is an example expanding on the explanation above
local boolean = false

if boolean then -- This won't print anything out because the conditions have not been met
print("Did it work?") -- That means that this also won't run! In the same way, if a PC or Console player joins the game, this will also not run
end

-- Let's move on!

We will use a property from the UIStroke called “Thickness” which determines how thick the stroke is.

if TouchEnabled then
UIStroke.Thickness = StrokeThickness -- This is a number.
end

Alrighty! Let’s put everything together!

local Player = game.Players.LocalPlayer
local PlayerGui = Player.PlayerGui
local ScreenGui = PlayerGui.ScreenGui

local UserInputService = game:GetService("UserInputService")
local TouchEnabled = UserInputService.TouchEnabled

local TextLabel = script.Parent
local UIStroke = TextLabel.UIStroke

local StrokeThickness = 1.5 -- Feel free to tinker around with this until it meets your likings
-- you can put whole number or decimal if you want

strokeThickness = 1

if TouchEnabled then
UIStroke.Thickness = StrokeThickness
end

-- If you don't want to set every single UIStroke's thickness in your game by repeating this, you can simply loop through all the descendants of the ScreenGui, and if they are a UIStroke, then change their thickness to your variable's value

for index, value in pairs(ScreenGui:GetDescendants()) do
if value:IsA("UIStroke") then  -- This basically detects if the value is a UIStroke or whatever class you put in there
value.Thickness = StrokeThickness -- This should autofill for you, because now the script sees that it could be of the class you requested for
end
end

And that is it! That is how you solve your UIStrokes appearing too big on mobile devices for your experiences! :+1:

Rate this tutorial!

  • 1 (Needs improvement)
  • 2 (Okay)
  • 3 (Good)
  • 4 (Amazing)

0 voters

Note: This tutorial is outdated. It has been update here

4 Likes

Pretty simple thing to do but very good tutorial for beginners

TLDR: Use UserInputService to check if Touch.Enabled = true and if so set the UIStroke thickness to something different by using either an IntValue or simply a number value.

1 Like

some issues for the code, here is a corrected version

if TouchEnabled then
UIStroke.Thickness = StrokeThickness
end

for index, value in pairs(ScreenGui:GetDescendants()) do
if value:IsA("UIStroke")  then
value.Thickness = StrokeThickness
end
end
1 Like

You only stated the property, you didn’t assign anything to it.

1 Like

touchê, guess that backfired

2 Likes

Sorry about some typos. I fixed them now. Thank you for reminding me though. I will look for more typos if I find any.

2 Likes

Sorry that I say it that harsh, but there’s a much better script from @bluebxrrybot

local studiosize = Vector2.new(1600,900) -- change this, I just pick random numbers


local function getratio()
    return workspace.CurrentCamera.ViewportSize.Y / studiosize.Y
end

local function onobject(stroke: UIStroke)
    if stroke:IsA("UIStroke") then
        stroke:SetAttribute("Thickness", stroke:GetAttribute("Thickness") or stroke.Thickness)
        stroke.Thickness = stroke:GetAttribute("Thickness") * getratio()
    end
end

local player = game.Players.LocalPlayer
for _, stroke in pairs(player.PlayerGui:GetDescendants()) do
    onobject(stroke)
end
player.PlayerGui.DescendantAdded:Connect(onobject)

I you script at least 3 important things are missing:
Screen Size of studio to calculate with
UI Stokes do not always have the same thickney
And do not calculate to 1 always, (different display sizes, the normal value changes etc…)
I would say this tutorial is pointless, the important calculations are missing!

2 Likes

It works either way, so what is the point?

Edit: I printed the UIStroke’s thickness before and after, so it does work. I’ll use this in my future games.

print(UIStroke.Thickness) -- Prints 3
stroke.Thickness = stroke:GetAttribute("Thickness") * getratio()
print(UIStroke.Thickness) -- Prints 1.1472222805023193
1 Like

This tutorial needs a pictures of the UIStroke appearing too big on mobile devices because the UIStroke works fine on mobile devices.

1 Like

What do you mean?

PC:
image

Mobile:
image

1 Like

oh, in this image its not the UIStroke that is big :rofl:
image
It’s the image of the bar that is small

Not sure :sweat_smile:
It’s a possibility though :sweat_smile:

1 Like

I think that you made a script that makes the bars smaller on mobile and forgot to do the same for the UIStroke.

1 Like

Thank you for the suggestion. I used this in Studio and it worked for all mobile devices.

2 Likes

So was i correct? if yes, please delete the topic in order not to waist dev’s time.

1 Like

I was not talking to you, I was referring to @Misterx113. This topic is closed now.

1 Like

Thats the point, its not true, it dosnt work right. Your script in the main post will not work properly.

1 Like

If it does, then show a video or screenshot, because for me it’s not.

1 Like

Sadly I cant event showcase it to you because the script has a error to, you forgot to close the for statement. Not only is the script logic wrong, also the script text. Also is screenGui not definied.

1 Like

After I fixed your script, you see exactly the problem that I saw and explained to you all the time without testing it and you were too ignorant to see it. After having a proper look at the code I have to say: it is simply absolute trash. tbh
Your script:


Orginale:

The script I send in this topic:

Without any script

1 Like

We’re trying to make the UIStroke smaller, not bigger. Your example looks off.

Edit: Look, do what works best for you, but don’t call other people’s way of doing things trash.
This works fine in Roblox Studio for me.

Even if yours is a better alternative, you still have no right to call someone else’s code downright trash. You also never tried tinkering around with the Thickness like I said. That’s on you.

Also this doesn’t even work on other screens. Not every screen resolution is of that of an iPad.

I just did this:

local Player = game.Players.LocalPlayer

local CurrentCamera = game.Workspace.CurrentCamera

local PlayerGui = Player.PlayerGui.MainUI

local Thickness = 2 -- Change this

local ViewportRatio = CurrentCamera.ViewportSize.Y / CurrentCamera.ViewportSize.Y

print(ViewportRatio * Thickness)

local UserInputService = game:GetService("UserInputService")
local TouchEnabled = UserInputService.TouchEnabled


for i, v in pairs(PlayerGui:GetDescendants()) do
	if v:IsA("UIStroke") then
		if TouchEnabled then
			v.Thickness = Thickness * ViewportRatio
		end
	end
end

It appears to work. For all mobile devices.

1 Like