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

Help with a simple color changing script?

Asked by
AmiracIe 175
9 years ago

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

Log in to vote
1
Answered by
l0cky2013 135
9 years ago

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)

Ad
Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

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

Log in to vote
0
Answered by 9 years ago
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.

Answer this question