I have a script similar to this, but it does NOT work. Can anyone help me?
function(OnKeyPressed) Local key = k if Game.Workspace.Player(OnKeyPressed) then Player.Humanoid.Health = - 25 end
You use the PlayerMouse event 'KeyDown'. The event is fired when a key is pressed, and you can only get the mouse from a LocalScript.
--Also, just a few things that were wrong with your script. --Firstly, when defining a local variable, you must have 'local' in lowercase letters. --Secondly, the Player isn't a child of the Workspace. What you're looking for is the Character, which is the 3D model of your Player. The Player's Character can be accessed through the player though, by the property 'Character'. With getting the Player from the Character, you can use the inbuilt 'GetPlayerFromCharacter' function to get a player from a character model. --Thirdly, functions run. They're not used in an if statement, if statements are used to see if something exists/is true. -- And finally, with decreasing values, you have to state what to decrease it from first. Otherwise, you're pretty much saying 'The character's health is equal to subtract 25' local Player = game.Players.LocalPlayer local Character = Player.Character local Mouse = Player:GetMouse() Mouse.KeyDown:connect(function(key) if key == "k" then Character.Humanoid.Health = Character.Humanoid.Health - 25 end end)
Apologies if this was unhelpful to you, if it was, please downvote and explain why :) Or just downvote if you just think I suck xD
you always need to follow the rules of scripting. Good try and you're doing well. Make sure you write "local" not Local, etc.