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

Why is this script not changing the color of MeshParts?

Asked by
asadefa 55
5 years ago

I am trying to make a script to cause a part of a tool to oscillate from blue to white:

EquippedEvent.OnServerEvent:Connect(function(Player, Tool)
    local C = Tool.HammerPart.HammerPart.Color
    while Tool.Parent == Player.Character do
        while C.r > 0 do
            C = Color3.new(C.r-2, C.g, C.
            wait(0.01)
        end
        wait(0.1)
        while C.r < 255 do
            C = Color3.new(C.r+2, C.g, C.b)
            wait(0.01)
     end
      wait(0.1)
  end
end)

I have tested it with print, and it seems correct but no visual changes have appeared. Please help me. What is wrong?

1 answer

Log in to vote
2
Answered by 5 years ago

You shouldn't set variables to properties, because it simply reads the property and then sets the variable to the value of the property. (that's probably a little confusing...)

For example. If the Transparency property of game.Workspace.Part is 1 and I write a line like

t = workspace.Part.Transparency
print(t)

The output then prints out 1. The variable isn't game.Workspace.Part.Transparency, it simply read the value of that property and set the variable to that value.

THEREFORE, what you need is to set the variable to the object and then reference properties of the object.

Effectively, it should look more like this:

EquippedEvent.OnServerEvent:Connect(function(Player, Tool)
    local C = Tool.HammerPart.HammerPart
    while Tool.Parent == Player.Character do
        while C.Color.r > 0 do
            C.Color = Color3.new((C.Color.r-2)/255, C.Color.g/255, C.Color.b/255)
            wait(0.01)
        end
        wait(0.1)
        while C.Color.r < 255 do
            C.Color = Color3.new((C.Color.r+2)/255, C.Color.g/255, C.Color.b/255)
            wait(0.01)
     end
      wait(0.1)
  end
end)

Also, I noticed while editing your code that you were going to get a weird result anyways since you forgot that when creating a new Color3 value you have to divide each rgb input by 255, since it looks for a number between 1 and 0 for each argument.

Hope this helps.

0
Instead of color3.new, you can use color3.fromRBG to get the desired result without the division by 255 SerpentineKing 3885 — 5y
Ad

Answer this question