Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How would I fix the script to change text color?

I have made a script that can change the ammo of a gun in a gui. The gui is set up but the problem is it won't change the colors of the text. It does it once in the script.

how would i make this where is ammo was under 12 it because red?
script.Parent.Changed:connect(function()
    if tonumber(script.Parent.Text) < 24 then
        script.Parent.TextColor3 = Color3.new(255, 255, 0)
    elseif tonumber(script.Parent.Text) < 12 then
        script.Parent.TextColor3 = Color3.new(255, 0, 0)
    else
        script.Parent.TextColor3 = Color3.new(0, 255, 0)
        end
end)

It's the if part, the first part, that works but the elseif doesn't work. I've tried it with a space in between but it still doesn't work. How could I fix it to make it work on both below 24 and 12?

4 comments

0

12 is below 24, so...

0

Color3.new() takes in values from 0-1. You are setting it at 255. Either divide the desired colour with 255 like this, (255/255, 0, 255/255), or simply put 1 to represent the whole number, like this (1, 0, 1); Additionally, if you dont want to have decimal numbers, consider switching over to Color3.fromRGB().

0

Ye but the if statement will return true if it is less than 24 thus the elseif not running

0

Delete your first comment and create a new comment / answer explaining both of these things then. TOo lazy to make a whole answer out of this. 

1 answer

✓ Accepted answer

Here's the correct answer.

script.Parent.Changed:connect(function()
    if tonumber(script.Parent.Text) < 24 and tonumber(script.Parent.Text) > 12 then
        script.Parent.TextColor3 = Color3.new(255, 255, 0)
    elseif tonumber(script.Parent.Text) < 12 then
        script.Parent.TextColor3 = Color3.new(255, 0, 0)
    else
        script.Parent.TextColor3 = Color3.new(0, 255, 0)
        end
end)

1 comment

0

Did you not bother to capitalise the c in connect? It should be Connect

This discussion is preserved as it was. New answers, comments, and votes are closed.