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
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)
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)
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)