This is the local script, and I am confused with line 6.
1 | player = game.Players.LocalPlayer |
2 | tool = script.Parent |
3 | tool.Equipped:connect( function (mouse) |
4 | mouse.KeyDown:connect( function (key) |
5 | if key = = "m" then |
6 |
7 | end |
8 | end ) |
9 | 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
Mouse.KeyDown is deprecated. Please do not use it!
Please use ContextActionService instead!
Here is an example:
01 | local Players = game:GetService( "Players" ) |
02 | local ContextActionService = game:GetService( "ContextActionService" ) |
03 |
04 | local player = Players.LocalPlayer |
05 | local tool = script.Parent |
06 |
07 | function onKeyPress(actionName, userInputState, inputObject) -- The new way we are detecting input |
08 | if actionName = = "M" and userInputState = = Enum.UserInputState.End then -- Fire when they let go of M |
09 | player.Character:BreakJoints() |
10 | end |
11 | end |
12 |
13 | local function ToolEquip(mouse) |
14 | ContextActionService:BindActionToInputTypes( "M" , onKeyPress, false , Enum.KeyCode.M) |
15 | end |
Add this line to your script at line 06
Grabs the character from the player and sets the humanoid's state to dead.
1 | Player.Character.Humanoid:ChangeState(Enum.HumanoidStateType.Dead) |
Another way to go about it, if you're wondering. Explanation's pretty self-explanatory.
01 | local tool = script.Parent |
02 | local player = game:GetService( 'Players' ).LocalPlayer |
03 |
04 | tool.Equipped:connect( function (mouse) -- When the player equips tool |
05 | mouse.KeyDown:connect( function (key) -- When a key is pressed |
06 | if string.byte(key) = = 109 then -- checks to see if "m" is pressed |
07 | player.Character:BreakJoints() -- Effectively kills the player |
08 | end |
09 | end ) |
10 | end ) |