How do i make it so my hand deals damage only when i press F button?
Asked by
3 years ago Edited 3 years ago
SCRIPT :
01 | local replicatedStorage = game:GetService( 'ReplicatedStorage' ) |
02 | local PunchingRemote = replicatedStorage:WaitForChild( 'Punch' ) |
03 | local anim 1 = Instance.new( 'Animation' ) |
04 | local anim 2 = Instance.new( 'Animation' ) |
10 | PunchingRemote.OnServerEvent:connect( function (plr) |
11 | local track 1 = plr.Character.Humanoid:LoadAnimation(anim 1 ) |
12 | local track 2 = plr.Character.Humanoid:LoadAnimation(anim 2 ) |
13 | local character = plr.Character |
14 | local humanoid = character:WaitForChild( 'Humanoid' ) |
15 | if var = = 1 and debounce = = false then |
17 | plr.leaderstats.Effort.Value = plr.leaderstats.Effort.Value + plr.Stats.Earnings.Value |
22 | elseif var = = 2 and debounce = = false then |
24 | plr.leaderstats.Effort.Value = plr.leaderstats.Effort.Value + plr.Stats.Earnings.Value |
31 | plr.Character.RightHand.Touched:connect( function (hit) |
32 | if hit.Parent.Humanoid and canDoDmg then |
33 | hit.Parent.Humanoid:TakeDamage(plr.Stats.Damage.Value) |
40 | plr.Character.LeftHand.Touched:connect( function (hit) |
41 | if hit.Parent.Humanoid and canDoDmg then |
42 | hit.Parent.Humanoid:TakeDamage(plr.Stats.Damage.Value) |
LocalScript :
1 | local UIS = game:GetService( 'UserInputService' ) |
2 | local replicatedStorage = game:GetService( 'ReplicatedStorage' ) |
3 | local remotePunch = replicatedStorage:WaitForChild( 'Punch' ) |
4 | UIS.InputBegan:connect( function (input, isTyping) |
5 | if isTyping then return end |
6 | if input.KeyCode = = Enum.KeyCode.F then |
7 | remotePunch:FireServer() |
Basically, when i go next to a play and my hand touches his body it deals damage anyway, and i want it to deal damage only when i press a certain key. Please teach me, i don t want a script i want an explanation so i can understand it and learn it for further projects !