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.

1player = game.Players.LocalPlayer
2tool = script.Parent
3tool.Equipped:connect(function(mouse)
4    mouse.KeyDown:connect(function(key)
5    if key == "m" then
6 
7    end
8end)
9end)

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:

01local Players = game:GetService("Players")
02local ContextActionService = game:GetService("ContextActionService")
03 
04local player = Players.LocalPlayer
05local tool = script.Parent
06 
07function 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
11end
12 
13local function ToolEquip(mouse)
14    ContextActionService:BindActionToInputTypes("M", onKeyPress, false, Enum.KeyCode.M)
15end
View all 22 lines...
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.

1Player.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.

01local tool = script.Parent
02local player = game:GetService('Players').LocalPlayer
03 
04tool.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)
10end)

Answer this question