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

Help with a simple color changing script?

My script is as follows:

Grass1=script.Parent

function onTouched(Grass1)
	Player=Grass1.Parent:findFirstChild("Humanoid")
	if Player~=nil then
		print("checkpoint reached")
if game.Workspace.Grass1.BrickColor==("Dark green") then
	print("checkpoint reached2")
	game.Workspace.Grass1.BrickColor=BrickColor.new("Grime")
	game.Workspace.Grass2.BrickColor=BrickColor.new("Dark green")
end
	
end
end 
Grass1.Touched:connect(onTouched)

There isn't anything wrong in the output. It never gets past checkpoint 2. I am a new scripter, so please don't be mean if I made a silly mistake :(

Anybody have an idea why the brick colors aren't changing?

3 answers

Hello. The error that I see is that you are not comparing the color withBrickColor.new, rather a string.

Fix

Grass1=script.Parent

function onTouched(Grass1)

    Player=Grass1.Parent:findFirstChild("Humanoid")
    if Player~=nil then
        print("checkpoint reached")
		if game.Workspace.Grass1.BrickColor==BrickColor.new("Dark green") then
   			 print("checkpoint reached2")
    			game.Workspace.Grass1.BrickColor=BrickColor.new("Grime")
   			 game.Workspace.Grass2.BrickColor=BrickColor.new("Dark green")
		end
	end
end

Grass1.Touched:connect(onTouched)

Grass1=script.Parent

function onTouched(Grass1)

    Player=Grass1.Parent:findFirstChild("Humanoid")
    if Player~=nil then
        print("checkpoint reached")
        if Grass1.BrickColor==BrickColor.new("Dark green") then
             print("checkpoint reached2")
                Grass1.BrickColor=BrickColor.new("Grime")
            Grass2.BrickColor=BrickColor.new("Dark green")
        end
    end
end

Grass1.Touched:connect(onTouched)

you dont need to game.Workspace.Grass1, cause that what just do nothing.

You are comparing your 'Grass1' BrickColor with a string instead of another BrickColor, as well as calling upon the Grass1 parameter wrong. It is a parameter, it already leads to what you want. Also you're setting a variable named Grass1 which value is the script's parent, but your parameter for the function is Grass1.

Line 7: if game.Workspace.Grass1.BrickColor==("Dark green") then

fix;

Line 7: if Grass1.BrickColor == BrickColor.new("Dark green") then

Full fix and shortenned a bit;

script.Parent.Touched:connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") ~= nil then
		print("Checkpoint reached")
		if script.Parent.BrickColor == BrickColor.new("Dark green") then
			print("Checkpoint reached(2)")
			script.Parent.BrickColor = BrickColor.new("Grime")
			game.Workspace.Grass2.BrickColor = BrickColor.new("Dark green")
		end
	end
end)

-Goulstem

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