Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

My script is not changing stroke color, how do I fix this issue?

Asked by 2 years ago
Edited 2 years ago

I was making a DarkRP game on Roblox which clearly isn't the most original idea, and when I wanted to make a halloween border thing for my GUI, it does not change color. This is what the code looks like:

local CurrentMonth = os.date("%m")

if CurrentMonth == 10 then
    script.Parent.Stroke.Color = Color3.fromRGB(255,155,0)
end

Extra notes: 1. The script does not throw any errors. 2. The script is in the Frame object holding the UIStroke object.

1 answer

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

the issue your having is related to the CurrentMonth being a string, not a number.

you can simply fix this issue by calling the tonumber function on the CurrentMonth variable

tonumber changes a string '124' to a number 124 (keep in mind the function breaks if there is anything other than numbers in the string)

example:

local CurrentMonth = os.date("%m")
print(
    type(CurrentMonth) -- returns the type of the variable
)
--> 'string'

print(
    tonumber(CurrentMonth) -- returns the integer 
)
--> 10

print(
    type(
        tonumber(CurrentMonth) -- returns the integer 
    )
)
--> number

tostring changes any object into a type (stringified), although i wont go into any deeper explanation of this.

to fix your issue, you have to do one quick change:

local CurrentMonth = tonumber(os.date("%m"))

if CurrentMonth == 10 then
    script.Parent.Stroke.Color = Color3.fromRGB(255,155,0)
end

here is a resource linking to the developer API that can explain this ten times better than i have https://create.roblox.com/docs/scripting/luau/strings

hopefully this solves your problem :)

0
I'll try this solution; thanks in advance! ArtyomAL3X 12 — 2y
Ad

Answer this question