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

Why does the background color turn white instantly?

Hello, every part of the script is responding well to eachother except the line where it changes the color to (30, 182, 20) which is a medium-dark green. Every time I run the script, it turns the button completely white, and the background color says (6500, 0, 0).

Player = game.Players.LocalPlayer --get the local player
color = script.Parent.Parent.Parent.Parent.Parent.Parent:WaitForChild("WhatColor")
script.Parent.MouseButton1Up:connect(function()
	
	
	if color.Value == "Green" then
		script.Parent.BackgroundColor3 = Color3.new(240, 0, 0)
		color.Value = "Red"
		script.Parent.Text = "Game Off"
		Player.Ingame.Value = false
		
	elseif color.Value == "Red" then
		
		script.Parent.BackgroundColor3 = Color3.new(30, 182, 20)
		color.Value = "Green"
		script.Parent.Text = "Game On"
		Player.Ingame.Value = true
	end
	
	
	


end)

1 comment

1 answer

✓ Accepted answer
Player = game.Players.LocalPlayer --get the local player
color = script.Parent.Parent.Parent.Parent.Parent.Parent:WaitForChild("WhatColor")
script.Parent.MouseButton1Up:connect(function()
    if color.Value == "Green" then
        script.Parent.BackgroundColor3 = Color3.fromRGB(240, 0, 0)
        color.Value = "Red"
        script.Parent.Text = "Game Off"
        Player.Ingame.Value = false
    elseif color.Value == "Red" then
        script.Parent.BackgroundColor3 = Color3.fromRGB(30, 182, 20)
        color.Value = "Green"
        script.Parent.Text = "Game On"
        Player.Ingame.Value = true
    end
end)

OR

Player = game.Players.LocalPlayer --get the local player
color = script.Parent.Parent.Parent.Parent.Parent.Parent:WaitForChild("WhatColor")
script.Parent.MouseButton1Up:connect(function()
    if color.Value == "Green" then
        script.Parent.BackgroundColor3 = Color3.new(240/255, 0/255, 0/255)
        color.Value = "Red"
        script.Parent.Text = "Game Off"
        Player.Ingame.Value = false
    elseif color.Value == "Red" then
        script.Parent.BackgroundColor3 = Color3.new(30/255, 182/255, 20/255)
        color.Value = "Green"
        script.Parent.Text = "Game On"
        Player.Ingame.Value = true
    end
end)

Either method above works, it gets the exact color value that you specify.

2 comments

0

use color3.fromRGB it's faster cuz you don't need to use math to put parameters in

0

use local variables

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