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

How would I fix the script to change text color?

Asked by 5 years ago
Edited 5 years ago

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?

0
12 is below 24, so... User#19524 175 — 5y
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()`. Zafirua 1348 — 5y
0
Ye but the if statement will return true if it is less than 24 thus the elseif not running User#19524 175 — 5y
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.  Zafirua 1348 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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)
0
Did you not bother to capitalise the c in connect? It should be Connect User#19524 175 — 5y
Ad

Answer this question