如何通过按下键盘上的键来杀死我自己的玩家?(Roblox)



正如标题所示,我正试图通过按下键盘上的按钮来杀死roblox中我自己的角色。我试过Humanoid.Health = 0player.Character.Head:remove(),但都不起作用!我目前的解决方案是:

local UserInputService = game:GetService("UserInputService")
local resetStand = IsKeyDown(Enum.KeyCode.Semicolon)
if IsKeyDown(Enum.KeyCode.Semicolon) = true then
player.Character.Head:remove()
end

IsKeyDown((是一个函数,它告诉当前是否持有键。这意味着当脚本启动时,它只会检查一次。

你要找的是一个键盘事件。每当输入(键盘、鼠标等(被触发时,就会触发。您所要做的就是检查输入是否是您的密钥:

local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(input, isTyping)
if not isTyping then --dont wanna acciedentally trigger when player is typing in chat
if input.KeyCode == Enum.KeyCode.Semicolon then --check if input was a semicolon
local char = game.Players.LocalPlayer.Character
char:BreakJoints() --break joints (oof)
end
end
end)

请确保该脚本是本地脚本。当我将它插入StarterPlayerScripts时,它对我有效,但还有许多其他地方也有效。

最新更新