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

Gui color not changing during certain conditions?

I want it to turn red upon a random number.

calltime = math.random(3,60)
prank = math.random(1,2)
phone = script.Parent


while true do
	wait(calltime)
	phone.Call:play()
	function onClicked(playerWhoClicked)
    phone.Call:Stop()
	phone.Pickup:Play()
	if prank == 1 then
		game.StarterGui.ScreenGui.Frame.TextLabel.TextColor3 = Color3.new(251,255,0)
	else
		game.StarterGui.ScreenGui.Frame.TextLabel.TextColor3 = Color3.new(255,0,0)
	end
	end
 
script.Parent.ClickDetector.MouseClick:connect(onClicked)
end

I already have a gui, and it has its own script to have its parent be the localplayer's playergui.

1 answer

✓ Accepted answer

The Color3 code has to be between 0 and 1. In order to do this do something like

game.StarterGui.ScreenGui.Frame.TextLabel.TextColor3 = Color3.new(251/255,255/255,0)

In addition, calling the number as a variable will cause it to switch only once. Re-update the variable after every time the function is ran.

Try not to run a function within a loop too. Run the function before the loop to ensure it to work the best. (Pull it out of the loop and put it in front)

Instead of doing,

game.StarterGui.ScreenGui.Frame.TextLabel.TextColor3 = Color3.new(251/255,255/255,0)

do,

playerWhoClicked.PlayerGui.ScreenGui.Frame.TextLabel.TextColor3 = Color3.new(251/255,255/255,0)

StarterGui will only access the server version, rather than the player's version.

5 comments

0

how do i do that?

0

thanks a bunch!

0

You could also use fromRGB so you don't have to divide; ie TextLabel.TextColor3 = Color3.fromRGB(251,255,0)

0

I want it to be a random color between red, and yellow. how do i do that?

0

Do math.random(0,255)

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