I want the target to be hit when the mouse is over it and x is pressed. I'm new to this part any help is greatly appreciated.
local plr = game.Players.LocalPlayer;
local mouse = plr:GetMouse();
local torso = plr.Character.Humanoid.Torso
function onKeyPress(actionName, userInputState, inputObject)
if userInputState == Enum.UserInputState.Begin then
torso.Velocity = torso.CFrame.lookVector*-63
plr.Character.Humanoid.Health = plr.Character.Humanoid.Health - 25
plr.Character.Humanoid.Sit = true
wait(5)
plr.Character.Humanoid.Sit = false
end
end
game.ContextActionService:BindAction("keyPress", onKeyPress, false, Enum.KeyCode.X)
mouse.Move:connect(function()
local X, Y = mouse.X, mouse.Y;
if mouse.Target and plr.Target.Humanoid.Health == - 25 and plr.Target.Humanoid.Sit then
if game.Players:GetPlayerFromCharacter(mouse.Target.Parent)
and X > script.Parent.AbsolutePosition.x and
Y > script.Parent.AbsolutePosition.y and
X < script.Parent.AbsolutePosition.x+script.Parent.AbsoluteSize.x and
Y < script.Parent.AbsolutePosition.y+script.Parent.AbsoluteSize.y
then
else
end
else
end
end)

15 comments
Im rlly happy thank you so so so much!
No problem! If it helped out, make sure to mark the answer as correct so we all know you have a working solution.
Oh ye and one more thing
I want the target to be pushed and also sit when pushed but can I just rename it then to target?And also putting cooldown between one push ( - 25 damage and the pushback
To make the person sit down, you can use the change state function on Humanoid: http://wiki.roblox.com/index.php?title=API:Class/Humanoid/ChangeState
To push the player back, check out the bodymovers: https://wiki.roblox.com/index.php?title=API:Class/BodyMover
yay Now the target also sits now I will do the bodymove part now
Good job! I'm glad you were able to figure that part out. And yes, I didn't add the sitting or the pushing to my script, it was just a layout for checking if the mouse is on the target and the user is pressing X.
Yes I already had a great start with your help I now really understand it I'm now making it so that the target not only gets pushed and sits but also makes a circle
Don't forget to select 'Accept answer' so other users know this question has been answered!
ye I do it directly when Im ready
Can you post on this thread with the code formatted please?
the code that I have right now?
I tried to understand the WIKI but I don't get it
So now I got it so far but its pretty bad it looks liek the target gets teleported not even pushed