v.ButtonPart.Touched:Connect(function(Hit)
if Hit:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(Hit.Parent)
if Values.OwnerValue.Value == player then
if v.ButtonPart.CanCollide == true and v.ButtonPart.Transparency == 0 then
if player:WaitForChild("leaderstats").Cash.Value >= v.Price.Value then
player.leaderstats.Cash.Value -= v.Price.Value
items[v.items.Value].Parent = Boughtitems
end
end
end
end
end)
我的按钮不起作用。
我认为这不起作用的原因是因为这行:
Hit:FindFirstChild("Humanoid")
。当您使用 .Touched:Connect(function())
时,函数的第一个参数是触及它的任何内容,因此如果您走过它,它将返回“LeftLeg”或类似的内容。你想要做的是在触及它的任何部分找到“Humanoid”,这绝对行不通。尝试将 if Hit:FindFirstChild("Humanoid") then
替换为 if Hit.Parent:FindFirstChild("Humanoid") then
。