【问题标题】:Fixing my color touch script for my roblox puzzle game修复我的 roblox 益智游戏的彩色触控脚本
【发布时间】:2021-08-12 16:44:36
【问题描述】:

所以我有一个基于街机经典 Q bert 的 roblox 益智游戏,我已经做了一段时间了,目标是改变砖块的所有颜色,同时避开敌人并获得高分,但我将添加我自己的一些功能,因此它不会变得重复,例如额外的任务,例如在平台上收集钥匙以解锁下一个级别的门,以及像钻石一样每 10 轮很少出现一次的秘密,收集一个给玩家一个额外的家伙和 1000 万分。

这就是游戏目前的样子https://streamable.com/na46cu 如您所见,我遇到的问题是颜色实际上确实发生了变化,但是当我再次跳上它时,它变回第一种颜色,在这种情况下为绿色,但我希望它保持在第一种颜色并使其在玩家再次跳上砖块之前不会改变.com/watch?v=9eXJWiNXpOo][2] .

我已经尝试了一些事情,比如添加计时器、去抖动甚至单独的脚本,到目前为止,这些都没有为我解决,我当然出去寻找其他人的问题,但到目前为止也有类似的问题我一直在努力寻找有同样问题的其他人。

  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

我不是最好的程序员,但我确实了解编程的基础知识,并且我尝试过各种编程语言,如 Python 和 c++,一旦你了解了所有这些基础知识,所有这些都不是那么难理解,而是发现问题的解决方案是真正棘手的部分,错误修复和故障排除也是如此。

我知道我可以尝试一个简单的去抖动系统,但这仍然不能解决问题,它只会使代码只运行一次并减慢它。

我一直在到处询问这个问题的解决方案,但我从来没有得到答案,所以我尝试了一次好的旧 Stackoverflow,看看这是否是我获得所需帮助的地方.

【问题讨论】:

    标签: lua game-development roblox


    【解决方案1】:

    这应该可以,试试吧

    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
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-12
      • 2021-11-13
      • 2017-02-17
      • 1970-01-01
      • 1970-01-01
      • 2012-05-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多