Hey guys, what’s wrong in my code? i’m trying to make a list where if you touches a part frame’s color changes, idk why change color is not working
LocalScript:
-- items
local it1 = script.Parent.item1
local it2 = script.Parent.item2
local it3 = script.Parent.item3
-- Touches parts
local tpart1 = game.Workspace.Touching1 -- RED
local tpart2 = game.Workspace.Touching2 -- BLUE
local tpart3 = game.Workspace.Touching3 -- GREEN
-- tables
local obj = {}
-- touches
tpart1.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
table.insert(obj,1,it1)
print("touches red part")
wait(5)
it1.BackgroundColor3 = BrickColor.new("Bright red")
wait(5)
print(obj)
end
end)
tpart2.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
table.insert(obj,1,it2)
print("touches blue part")
wait(5)
it2.BackgroundColor3 = BrickColor.new("Bright blue")
wait(5)
print(obj)
end
end)
tpart3.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
table.insert(obj,1,it3)
print("touches green part")
wait(5)
it3.BackgroundColor3 = BrickColor.new("Bright green")
wait(5)
print(obj)
end
end)
-- end touches
local remove = game.Workspace.remove
tpart1.TouchEnded:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
table.remove(obj,1)
print("item 1 has been removed")
wait(2)
table.remove(obj,1)
print("item 2 has been removed")
wait(2)
table.remove(obj,1)
print("item 3 has been removed")
wait(2)
print("All items has been removed!")
end
end)
You’re welcome, happy to help ^ - ^
As a bonus, this is better:
local debonce = true
workspace[Name].Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and debonce then
debonce = false
for i=1, #obj do
print("item", i, "has been removed")
wait(2)
end
obj = {}
print("All items has been removed!")
debonce = true
end
end)