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

BrickColor changing script won't work online, why?

Asked by 9 years ago

There is no errors shown by output or developer console.

while true do wait()

parts = script.Parent.Parent:GetChildren() for x = 1, #parts do if parts[x].Name == "PartC" then parts[x].BrickColor = script.Parent.Value end end end

What am I doing wrong?

0
Please put in a code block EzraNehemiah_TF2 3552 — 9y
0
Hello? I answered this a day ago. You just have 3 ends. You only need 2. EzraNehemiah_TF2 3552 — 9y

1 answer

Log in to vote
1
Answered by 9 years ago

A few tips:

1.) while wait() do is the same as while true do wait(). You could also use the heartbeat event from the runservice.

--All of these are practically the same.

while wait() do
end
--These 2 are the same
while true do
    wait()
end

-------------------------------------------------------------------------------
game:GetService("RunService").Heartbeat:connect(function()--This is slower by 0.004 seconds.
end

2.) You can use pairs instead of for i = 1,#..etc.

for i = 1,#game.Players:GetChildren()
end
--same
for _,player in pairs(game.Players:GetChildren()) do
end

3.) You can use the :IsA() to see if it's a part.

if workspace.Part:IsA("Part") then --If it's a part
    print("Part's class name is Part")
end

if workspace.Part:IsA("BasePart") then
    print("Part could be a wedge, corner wedge, cylinder, Sphere, Regular Part, etc.")
end

With all these tips we can finally fix your problem.


Problem: You have too many ends! You only need 2 for this script. Also, check to see if script.Parent is a BrickColor Value.

parts = script.Parent.Parent:GetChildren()

for _,x in pairs(parts) do
    if x:IsA("Part") then
        x.BrickColor = script.Parent.Value
    end
end --You only need 2 ends. Not 3.
Ad

Answer this question