【问题标题】:Roblox, damaging a player upon contact with a partRoblox,在接触零件时伤害玩家
【发布时间】:2018-09-14 21:30:56
【问题描述】:

我的代码:

local UIS = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Activation = 
Instance.new("Sound",game.Players.LocalPlayer.Character.Head)
local char = Player.Character
local hum = char.Humanoid
local root = char.HumanoidRootPart

UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.F then
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://1581972610"
local animTrack = hum:LoadAnimation(animation)
animTrack:Play()
Activation.SoundId = "rbxassetid://1581091676" --Plays Mangekyou Sharingan Activation Sound.
Activation:Play()
wait(0.3)       
game.Players.LocalPlayer.Character.Head.face.Texture = "rbxassetid://76285632" --When F is pressed, face texture changes to sharingan decal.
game:GetService("Chat"):Chat(Player.Character.Head, "Mangekyou Sharingan!")
end
end)

UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.R then
Activation.SoundId = "rbxassetid://1580990602" --Plays Amaterasu Activation Sound.
Activation:Play()
game:GetService("Chat"):Chat(Player.Character.Head, "Amaterasu!")
local Target = Instance.new("Part") --makes a part
Target.CFrame = Mouse.Hit; --Makes part spawn at the mouse's current location in game
Target.Parent = game.Workspace
Target.Transparency = 1 
Target.Anchored = true 
Target.CanCollide = false 



local Amaterasu = Instance.new("Fire")
Amaterasu.Parent = game.Workspace.Part
Amaterasu.Color = Color3.new(0,0,0)
Amaterasu.SecondaryColor = Color3.new(0,0,0) --amaterasu properties
Amaterasu.Size = 25

local R = Instance.new("RocketPropulsion") --rocket propulsion, parents amaterasu
R.Parent = Amaterasu
R.MaxThrust = 300
R.ThrustP = 30
R:Fire()
end
end)

 UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.G then
game.Players.LocalPlayer.Character.Head.face.Texture = "rbxassetid://22557247" --When G is pressed, face texture changes back to normal.(leaves face blank isnt working :/)
end
end)

我正在处理这个脚本中的第二个函数,如果按下“r”键就会激活该函数。该功能通过按“r”键使部分产生到鼠标当前位置,其中包含火焰。

这一切正常。我希望产生的火焰能够对接触到的任何玩家造成一定的生命值,在这种情况下,我希望伤害为 100 点生命值。

【问题讨论】:

  • 这主要是复制粘贴of your question from two hours earlier。该代码还在第三个问题中提供了大约七个小时前的第三个问题。因此,我会说您提出问题的方式基本上会产生重复的材料,并且可能会产生重复的工作。
  • 我很欣赏发布相同(或相似)的问题可能会增加您获得答案的机会,但请注意,Stack Overflow 是经过精心策划的,并非所有问题都被接受。对于它的价值,我的建议是在再次发布之前等待获得一个问题的答案。您可能会发现由于先前的问题得到解决,问题变得多余。

标签: lua scripting roblox


【解决方案1】:

我相信您正在寻找的是被触动了 - 请参阅创建一个危险的陷阱:https://wiki.roblox.com/index.php?title=Creating_Traps_and_Pickups

文档中提供的示例:

local trapPart = script.Parent
local function onPartTouch(otherPart)

    local partParent = otherPart.Parent
    local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")

    if ( humanoid ) then
        -- Set player's health to 0
        humanoid.Health = 0
    end
end

trapPart.Touched:Connect(onPartTouch)

但免责声明 - 不是 Roblox 开发人员(现在只是在窃听一个)。

祝你好运。

【讨论】:

    【解决方案2】:

    在设置属性之前不要让你的父母,否则会导致性能滞后

    【讨论】:

      猜你喜欢
      • 2020-09-03
      • 2019-11-19
      • 2020-05-18
      • 2017-06-29
      • 2021-11-09
      • 2021-10-17
      • 2022-10-05
      • 2021-08-05
      • 1970-01-01
      相关资源
      最近更新 更多