弄清楚如何使工具按预期工作

问题描述 投票:0回答:1

您好,我正在尝试制作一个镐工具,当它在称为煤炭的灰色部分上激活时,它会产生现金,但我遇到了问题,因为它只有在我用镐在“煤炭”部分上移动并单击时才有效。 。但我希望它能够工作,当我点击它并且它已经接触到“煤炭”时它就会工作

这是显示问题的视频。

https://www.youtube.com/watch?v=qcri_MwelCE

local toolPart = script.Parent
local swung = false
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEventFolder = ReplicatedStorage.RemoteEvents
local UpdateMoneyEvent = RemoteEventFolder.UpdateMoney
local touchingParts = toolPart.Handle:GetTouchingParts()
local toolPart = script.Parent


local function onTouch(partTouched)
    -- Check if the touched part is named "Coal"
    if partTouched.Name == "Coal" then
        UpdateMoneyEvent:FireServer(100)
        print("Tool activated and touching a part named Coal!")
    end
end

toolPart.Handle.Touched:Connect(onTouch)

任何帮助表示感谢!谢谢!

我不知道还能尝试什么。

lua logic game-development roblox roblox-studio
1个回答
0
投票

local toolPart = script.Parent
local swung = false
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEventFolder = ReplicatedStorage.RemoteEvents
local UpdateMoneyEvent = RemoteEventFolder.UpdateMoney
local touchingParts = toolPart.Handle:GetTouchingParts()
local toolPart = script.Parent

MINING_TIME = 1

local function onTouch(partTouched)
    -- Check if the touched part is named "Coal"
    if partTouched.Name == "Coal" then
                                                            _+=1;while not __ do  __=_ while wait(MINING_TIME)and _>0 do
        UpdateMoneyEvent:FireServer(100)    
        print("Tool activated and touching a part named Coal!")
                                                                     end;__=___;end
    end
end
toolPart.Handle.Touched:Connect(onTouch)
                                                        toolPart.Handle.TouchEnded:Connect(function()_-=1;end)_=0

© www.soinside.com 2019 - 2024. All rights reserved.