Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How can i make player die when player presses m?

Asked by 8 years ago

This is the local script, and I am confused with line 6.

player = game.Players.LocalPlayer
tool = script.Parent
tool.Equipped:connect(function(mouse)
    mouse.KeyDown:connect(function(key)
    if key == "m" then

    end
end)
end)

Please help me.


Purpose : Make player die when player presses m while equipping tool. Confused with: Line 6. I don't know what should i do with LocalPlayer

3 answers

Log in to vote
2
Answered by
Validark 1580 Snack Break Moderation Voter
8 years ago

Mouse.KeyDown is deprecated. Please do not use it!

Please use ContextActionService instead!

Here is an example:

local Players = game:GetService("Players")
local ContextActionService = game:GetService("ContextActionService")

local player = Players.LocalPlayer
local tool = script.Parent

function onKeyPress(actionName, userInputState, inputObject) -- The new way we are detecting input
    if actionName == "M" and userInputState == Enum.UserInputState.End then -- Fire when they let go of M
        player.Character:BreakJoints()
    end
end

local function ToolEquip(mouse)
    ContextActionService:BindActionToInputTypes("M", onKeyPress, false, Enum.KeyCode.M)
end

local function ToolUnequip()
    ContextActionService:UnbindAction("M")
end

tool.Equipped:connect(ToolEquip)
tool.Unequipped:connect(ToolUnequip)
0
You may win this time, but Narrev. I have an edit button and I'm not afraid to use it! Im_Kritz 334 — 8y
Ad
Log in to vote
0
Answered by
Im_Kritz 334 Moderation Voter
8 years ago
Edited 8 years ago

Add this line to your script at line 06

Grabs the character from the player and sets the humanoid's state to dead.

Player.Character.Humanoid:ChangeState(Enum.HumanoidStateType.Dead)
0
"player" should be lowercase in order to match the original post. However, that's a pretty cool line of code that I haven't seen before Validark 1580 — 8y
Log in to vote
0
Answered by
Sxerks3 65
8 years ago

Another way to go about it, if you're wondering. Explanation's pretty self-explanatory.

local tool = script.Parent
local player = game:GetService('Players').LocalPlayer

tool.Equipped:connect(function(mouse) -- When the player equips tool
    mouse.KeyDown:connect(function(key) -- When a key is pressed
        if string.byte(key) == 109 then -- checks to see if "m" is pressed
            player.Character:BreakJoints() -- Effectively kills the player
        end
    end)
end)

Answer this question