我制造了一支手枪,可以发射出一个部件,如果一个人形机器人接触到这个部件,他就会受到伤害,但我不想让玩家在接触到这个部件时死亡,我已经尝试过使用~=操作符,但它没有工作。这是代码
local db = false
game:GetService("ReplicatedStorage").RemoteEvent.OnServerEvent:Connect(function(Player, Hit)
local Shot = Instance.new("Part")
Shot.BrickColor = BrickColor.new("New Yeller")
Shot.CanCollide = false
local BackPack = Player.Character
Shot.Position = BackPack.Tool.Part.Position
Shot.Shape = Enum.PartType.Block
Shot.Size = Vector3.new(0.34, 0.228, 2)
local VectorForce = Instance.new("VectorForce")
local Attach = Instance.new("Attachment", Shot)
VectorForce.Attachment0 = Attach
VectorForce.RelativeTo = Enum.ActuatorRelativeTo.World
VectorForce.Force = CFrame.lookAt(BackPack.Tool.Part.Position, Hit.Position).LookVector * 500
VectorForce.Parent = Shot
if not db then
db = true
Shot.Touched:Connect(function(hsit)
if hsit:FindFirstChild("Humanoid") ~= Player.Character.Humanoid then
hsit.Parent.Humanoid.Health = hsit.Parent.Humanoid.Health-5
task.wait(2)
db = false
end
end)
end
Shot.Parent = workspace
game.Debris:AddItem(Shot, 3)
task.wait(2)
db = false
end)发布于 2022-07-23 13:13:26
if hsit:FindFirstChild("Humanoid") ~= Player.Character.Humanoid then将此更改为
if hsit.Parent and hsit.Parent:FindFirstChild('Humanoid') ~= Player.Character.Humanoid then发布于 2022-07-23 13:08:26
if Player.Character.Humanoid.Health > 5 then
-- damage player
end这应该能行。用可变基准或损坏常数替换5。
https://stackoverflow.com/questions/73090984
复制相似问题