0
votes

So I have a roblox puzzle game that I have been working on for a while now on based on the arcade classic Q bert where the goal is to change all the colours of the bricks while avoiding enemies and getting a high score but I will be adding some features of my own so it does not get as repetitive such as additional tasks like collecting keys on platforms to unlock the door to the next level and secrets like a diamond that rarely appears once every 10 rounds and collecting one gives the player an extra dude and 10 million points.

This is how the game looks so far https://streamable.com/na46cu The issue I am having as you can see is that the colours do in fact change but when I jump on it again it changes back to the first colour it changes to which in this case is green but I want it to stay on the first colour and make it so that it does not change until the player jumps on the brick again and later on in the game I want it to become more complex and puzzle like as the game goes on like in this example [https://www.youtube.com/watch?v=9eXJWiNXpOo][2] .

I have tried a few things like adding timers ,debounces and even separate scripts alltogether none of which have worked out for me so far and I of course went out looking for a question from somebody else that had a similar problem but so far I have been struggling to find anybody else that has the same problem.

  local module = {} --module for the modulescript and for loop is created 
local CollectionService = game:GetService("CollectionService")
for _, part,brick in pairs (CollectionService:GetTagged("blocks")) 
do 


    part.Touched:Connect(function(hit) --Part connects with the touched property to the function with the parameter hit
            
    
        if (hit.Parent:FindFirstChild("Humanoid"))
        then  
                
            part.BrickColor = BrickColor.new ("Bright green")
            
            wait (2)
            part.BrickColor = BrickColor.new ("Eggplant")
                
        --  local sound = workspace.Sound -- use "local sound = workspace.Sound", if there is already a sound object in the workspace
            --sound.SoundId = "rbxassetid://4797903038" --replace quoted text with whatever sound id you need to use
        
            

                --sound:Play()
            
        
                
                
            end 








            end) 

end


--      end)
--end

 

return module

I am not the best programmer but I do know the basics of programming and I have tried out various programming languages like Python and c++ all of which are not all that hard to understand once you know the basics of it all but finding out the solution to the problem is the really tricky part and so is bug fixing and troubleshooting.

I do know I could try a simple debounce system but that still does not solve the problem and it only makes it so the code only runs once and slows it down.

I have been asking all over the place for a solution to this problem but I never got an answer to it so I am trying on good old Stackoverflow for once to see if this will be the place where I get the help I need.

1

1 Answers

0
votes

this should work, try it

local module = {} --module for the modulescript and for loop is created 
local CollectionService = game:GetService("CollectionService")
local DidParts = {} -- Initializing another table to check if the part is already in it
for _, part,brick in pairs(CollectionService:GetTagged("blocks")) do 
    part.Touched:Connect(function(hit) --Part connects with the touched property to the function with the parameter hit


        if hit.Parent:FindFirstChild("Humanoid") then  
            if table.find(DidParts,part) then
                return -- checking if the part isnt in the table if it is then return
            end
            
            part.BrickColor = BrickColor.new("Bright green")

            wait(2)
            part.BrickColor = BrickColor.new("Eggplant")
            table.insert(DidParts,part) -- when all the code has finished insert it in the table
            --  local sound = workspace.Sound -- use "local sound = workspace.Sound", if there is already a sound object in the workspace
            --sound.SoundId = "rbxassetid://4797903038" --replace quoted text with whatever sound id you need to use



            --sound:Play()




        end 

    end) 

end


--      end)
--end



return module