frrazers
(Frazer)
September 16, 2020, 4:47pm
#1
Hey! I’m trying to find all parts in a folder, and change their colour. Here is a shortened version of my script.
local neonparts = game.Workspace.NeonParts:GetChildren()
Event.OnServerEvent:Connect(function()
neonparts.Color = BrickColor.new("Lime green")
end)
Any ideas on why this doesn’t work? I have also tried :GetDescendants()
and that did not work either.
If you need anymore info just ask.
1 Like
kingdom5
(kingdom5)
September 16, 2020, 4:54pm
#2
neonparts holds an a table of children and you are also passing the wrong type to Color.
I am not too sure why you need an event for this?
You would want to use something along the lines of this though you should make changes where you want.
Event.OnServerEvent:Connect(function()
local parts = game.Workspace.NeonParts:GetChildren() -- array of children
local newColor = Color3.fromRGB(0, 255, 0) -- green color3 roblox data type
for _, part in pairs(parts) do
part.Color = newColor -- set color
end
end)
2 Likes
Loop through the ‘neonparts’ using For Loops , :GetChildren()
returns a table of all the instances that are children of the part. Here is an example code:
local instances = workspace.Part:GetChildren();
local function get_Certain_Part()
for _, v in ipairs(instances) do
if tostring(v.Name) == "Part3" then
return v
else
end
end
end
local part = get_Certain_Part()
part:Destroy() -- Destroys the child instance that is called 'Part3'.
4 Likes
vsefu1
(yen)
September 16, 2020, 4:55pm
#4
Do for i, v in pairs() for the neonparts.
local neonparts = game.Workspace.NeonParts:GetChildren()
Event.OnServerEvent:Connect(function()
for i, v in pairs(neonparts) do
v.Color = Color3.fromRGB(0,255,0)
end
end)
4 Likes
frrazers
(Frazer)
September 16, 2020, 4:59pm
#5
I use an event for the script I am using, I just shortened it.
I got the following error.
1 Like
Did you used the scripts that they sended to you?
1 Like
frrazers
(Frazer)
September 16, 2020, 5:01pm
#7
I edited them a bit to fit into my whole script I am using.
1 Like
vsefu1
(yen)
September 16, 2020, 5:01pm
#8
Can i see your code that you put?
1 Like
frrazers
(Frazer)
September 16, 2020, 5:02pm
#9
Sure.
This is the whole script.
(I removed the color changing parts code)
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Points = Instance.new("IntValue")
Points.Name = "Points"
Points.Parent = leaderstats
local Wins = Instance.new("IntValue")
Wins.Name = "Wins"
Wins.Parent = leaderstats
end)
local Event = game.ReplicatedStorage:WaitForChild("GivePoints")
Event.OnServerEvent:Connect(function(player,amount,name)
game.Players:FindFirstChild(name):WaitForChild("leaderstats").Points.Value = game.Players:FindFirstChild(name):WaitForChild("leaderstats").Points.Value + amount
print("Added "..amount.." points to '"..name.."'")
local plight1 = game.Workspace:FindFirstChild(name).N2
local plight2 = game.Workspace:FindFirstChild(name).N1
local bg = game.Workspace:WaitForChild(name).DisplayName.SurfaceGui.Main
plight1.Color = Color3.fromRGB(0, 255, 0)
plight2.Color = Color3.fromRGB(0, 255, 0)
bg.BackgroundColor = BrickColor.new("Lime green")
wait(2)
bg.BackgroundColor = BrickColor.new(255, 255, 255)
plight1.Color = Color3.fromRGB(255, 255, 0)
plight2.Color = Color3.fromRGB(255, 255, 0)
end)
2 Likes
vsefu1
(yen)
September 16, 2020, 5:04pm
#10
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Points = Instance.new("IntValue")
Points.Name = "Points"
Points.Parent = leaderstats
local Wins = Instance.new("IntValue")
Wins.Name = "Wins"
Wins.Parent = leaderstats
end)
local Event = game.ReplicatedStorage:WaitForChild("GivePoints")
Event.OnServerEvent:Connect(function(player,amount,name)
game.Players:FindFirstChild(name):WaitForChild("leaderstats").Points.Value = game.Players:FindFirstChild(name):WaitForChild("leaderstats").Points.Value + amount
print("Added "..amount.." points to '"..name.."'")
local plight1 = game.Workspace:FindFirstChild(name).N2
local plight2 = game.Workspace:FindFirstChild(name).N1
local bg = game.Workspace:WaitForChild(name).DisplayName.SurfaceGui.Main
plight1.Color = Color3.fromRGB(0, 255, 0)
plight2.Color = Color3.fromRGB(0, 255, 0)
bg.BackgroundColor = Color3.fromRGB(0,255,0)
wait(2)
bg.BackgroundColor = Color3.fromRGB(255, 255, 255)
plight1.Color = Color3.fromRGB(255, 255, 0)
plight2.Color = Color3.fromRGB(255, 255, 0)
end)
Tell me if didn’t work.
1 Like
frrazers
(Frazer)
September 16, 2020, 5:15pm
#11
You changed
bg.BackgroundColor = Color3.fromRGB(0,255,0)
wait(2)
bg.BackgroundColor = Color3.fromRGB(255, 255, 255)
This part doesn’t need changing as it works perfectly fine before.
Hopefully this image explains what everything is a little bit better.
I am trying to change the Neon Parts
1 Like
Can you put back the changing code to the script and show it, that’s what I want to see.
2 Likes
frrazers
(Frazer)
September 16, 2020, 5:21pm
#13
The code from @vsefu1 that I tweaked a lil bit.
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Points = Instance.new("IntValue")
Points.Name = "Points"
Points.Parent = leaderstats
local Wins = Instance.new("IntValue")
Wins.Name = "Wins"
Wins.Parent = leaderstats
end)
local Event = game.ReplicatedStorage:WaitForChild("GivePoints")
local neonparts = game.Workspace.NeonParts:GetChildren()
Event.OnServerEvent:Connect(function(player,amount,name)
game.Players:FindFirstChild(name):WaitForChild("leaderstats").Points.Value = game.Players:FindFirstChild(name):WaitForChild("leaderstats").Points.Value + amount
print("Added "..amount.." points to '"..name.."'")
local plight1 = game.Workspace:FindFirstChild(name).N2
local plight2 = game.Workspace:FindFirstChild(name).N1
local bg = game.Workspace:WaitForChild(name).DisplayName.SurfaceGui.Main
plight1.Color = Color3.fromRGB(0, 255, 0)
plight2.Color = Color3.fromRGB(0, 255, 0)
bg.BackgroundColor = BrickColor.new("Lime green")
for i, v in pairs(neonparts) do
v.Color = Color3.fromRGB(0,255,0)
end
end)
wait(2)
bg.BackgroundColor = BrickColor.new(255, 255, 255)
plight1.Color = Color3.fromRGB(255, 255, 0)
plight2.Color = Color3.fromRGB(255, 255, 0)
end)
1 Like
Why you have two ends in the loop?
2 Likes
Also bg is a gui right? I dont think that you can set BackgroundColor to a BrickColor
2 Likes
frrazers
(Frazer)
September 16, 2020, 5:27pm
#16
Oh yeah! I didn’t see that, I removed the second one and it worked. Thanks for pointing that out.
1 Like