I have a local brick in my lobby which I’m trying to change the color of based on if the player is touching the brick or not. I’m using a destroy loop, but I dislike the way it changes the texture of the brick. Is there another way to update the color?
while true do
if game.Workspace.CurrentCamera:FindFirstChild("base") ~= nil then return end
Clone = Model:Clone()
Clone.Parent = game.Workspace.CurrentCamera
Clone.BrickColor = colorstatus
wait(1)
game.Workspace.CurrentCamera:FindFirstChild("base"):Destroy()
end
I’m not exactly sure how to do that, I tried adding:
while true do
if not game.Workspace.CurrentCamera:FindFirstChild("base") ~= nil then
game.Workspace.CurrentCamera:FindFirstChild("base").BrickColor = colorstatus
wait(1)
end
end
Because the first part is for if the brick does not exist. But this seems to not work.
Why not bind the color change directly to the Touched and TouchEnded events, or however else you are detecting if the player is standing on the platform?
Ahhh thanks… sometimes I find myself making things more complicated then needed.
local function onTouch(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
game.Workspace.CurrentCamera:FindFirstChild("base").BrickColor = BrickColor.new("Bright green")
end
end
local function onTouchEnded(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
game.Workspace.CurrentCamera:FindFirstChild("base").BrickColor = BrickColor.new("Fossil")
end
end
part.Touched:Connect(onTouch)
part.TouchEnded:Connect(onTouchEnded)