微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

修复我的 roblox 益智游戏的颜色触摸脚本

如何解决修复我的 roblox 益智游戏的颜色触摸脚本

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

这是目前为止游戏的样子https://streamable.com/na46cu 正如您所看到的,我遇到的问题是颜色确实发生了变化,但是当我再次跳上它时,它又变回了第一种颜色,在这种情况下它变为绿色,但我希望它保持第一种颜色并使其在玩家再次跳上砖块之前不会改变,然后在游戏中我希望它变得更加复杂和令人困惑,就像这个例子中的游戏一样[https://www.youtube .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 一次,看看这是否是我获得所需帮助的地方.

解决方法

应该可以,试试吧

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。