I’m trying to write a function that takes in an array of UIStrokes as an argument and scales their thickness depending on the platform (screen rez size)
If I don’t scale it the UIStrokes just look really thick on smaller screens and really thin on bigger screens
What I’ve got so far:
function F.ScaleUIStrokes(UIStrokes)
for _, UIStroke in UIStrokes do
UIStroke.Thickness = UIStroke.Thickness
end
end
so how can I change this so for example it lowers the thickness the perfect amount for mobile players
EDIT:
By the way it must be dependant on the absolute size of the Parent not on the overal screen size / camera size.
This is because there are parts of the game where the buttons with the UIStrokes get smaller
after they get smaller I run them through this function.
If it were based on camera size it won’t account for the Parent size
hmm. Try putting a invisible frame in StarterGui and set its size to {1, 0,}{1, 0} so it goes across the screen. then define it in that script and get its AbsoluteSize. Divide your UIStroke by your screen y and then multiply the result by the AbsoluteSize’s Y. this should work. if you get anything funny reply to me!
An easier option would be to just get the absolutesize of the ScreenGui.
But this doesn’t account for the parent getting smaller as if the parent of the UIStroke get’s smaller the uistroke won’t get less thick as the absolutesize of the ScreenGui is constant
this is what i did, i tested it in studio and it works perfectly.
while wait() do
size = script.Parent.Parent.AbsoluteSize
button = script.Parent
width = 5
num = width/432 -- this is the max Y of my screen. change it to yours.
button.BorderSizePixel = num * size.Y
end
I doni’t know how I feel about running something every single frame when It only needs to run at certain times.
Also remember to always use task.wait() and not wait()
i still dont know the difference between task.wait() and wait(). can you explain it to me please? i tried reading on it but there were many mixed answers.
running it each frame shouldn’t affect preformance by the way, its a very short and simple piece of code. you can try and check and see if the AbsoluteSize is the same as it was on the previous frame. if it isnt, run the script. ill write one now.
wait() is the old one - to make this clear there is no reason to use it anymore
the only reason it’s still in the Roblox scripting language is because very old games use it and if they took it away it would cause them to error
if you do wait() with no arguments it generally will wait about 1/30 of a second
task.wait() waits even less time by waiting about 1/60 of a second.
This is means it is guaranteed to stop the yield by the next frame
task.wait() is the only one you should use but keep in mind a task.wait() loop will run more frequently than a wait() loop so if you want it to run slower just provide an argument
task.wait(0.0166)
will be about the same as
wait()
but all you really need to know is to only use the task.wait()
task was a fairly new module that added better versions of existing functions
for example task.wait()
on that note spawn() is another one where you should only do task.spawn and never spawn as the task. ones are newer and better
size = script.Parent.Parent.AbsoluteSize
old = nil
border()
while task.wait() do
while old == size do task.wait() end
border(5)
end
function border(width)
size = script.Parent.Parent.AbsoluteSize
button = script.Parent
local num = width/432
button.BorderSizePixel = num * size.Y
old = size
end