Skip to content
TheChatArchiveThe Chat Archive
gpt-4-0314· OpenAIAi2 WildChat-4.8M (AI2)

Write me a roblox script when player click on block then block become blue

  1. User

    Write me a roblox script when player click on block then block become blue

  2. Assistant

    -- Create a function to handle the 'Touched' event local function onTouch(part) -- Check if the 'Touched' part is a block, and add a ClickDetector if it doesn't have one yet if part.Name == "Block" and part:FindFirstChild("ClickDetector") == nil then local clickDetector = Instance.new("ClickDetector", part)

        -- Create a ClickDetector event listener
        clickDetector.MouseClick:Connect(function(player)
            -- Check if the block isn't already blue and change its color to blue
            if part.BrickColor ~= BrickColor.new("Bright blue") then
                part.BrickColor = BrickColor.new("Bright blue")
            end
        end)
    end
    

    end

    -- Create a function to traverse all parts in the Workspace local function searchPartsInWorkspace(workspace) for _, part in ipairs(workspace:GetChildren()) do -- Check if it's a Model, BasePart or MeshPart if part:IsA("Model") or part:IsA("BasePart") or part:IsA("MeshPart") then onTouch(part) end

        -- Recursively search for parts in the Model
        if part:IsA("Model") then
            searchPartsInWorkspace(part)
        end
    end
    

    end

    -- Call the searchPartsInWorkspace function searchPartsInWorkspace(workspace)