Roblox,在与部件接触时损坏玩家

时间:2018-04-05 06:55:37

标签: lua scripting roblox

我的代码:

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健康。

2 个答案:

答案 0 :(得分:0)

我相信你所寻找的是感动 - 请参阅创建一个危险的陷阱: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开发者(现在只是在窃听)。

祝你好运。

答案 1 :(得分:0)

在设置属性之前不要创建父级,否则会导致性能滞后