Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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 :

01local replicatedStorage = game:GetService('ReplicatedStorage')
02local PunchingRemote = replicatedStorage:WaitForChild('Punch')
03local anim1 = Instance.new('Animation')
04local anim2 = Instance.new('Animation')
07local var = 1
08local debounce = false
09local canDoDmg = true
10PunchingRemote.OnServerEvent:connect(function(plr)
11    local track1 = plr.Character.Humanoid:LoadAnimation(anim1)
12    local track2 = plr.Character.Humanoid:LoadAnimation(anim2)
13    local character = plr.Character
14    local humanoid = character:WaitForChild('Humanoid')
15    if var == 1 and debounce == false then
View all 56 lines...

LocalScript :

1local UIS = game:GetService('UserInputService')
2local replicatedStorage = game:GetService('ReplicatedStorage')
3local remotePunch = replicatedStorage:WaitForChild('Punch')
4UIS.InputBegan:connect(function(input, isTyping)
5    if isTyping then return end
6    if input.KeyCode == Enum.KeyCode.F then
7        remotePunch:FireServer()
8        end
9end)

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 !

0
what did it do in reality, not expectations Xapelize 2658 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

You should disconnect the Touched event when its called so that it doesn't fire the function until you press F again

01local connectionRight, connectionLeft
02 
03connectionRight = plr.Character.RightHand.Touched:Connect(function(hit)
04    if hit.Parent.Humanoid and canDoDmg then
05        hit.Parent.Humanoid:TakeDamage(plr.Stats.Damage.Value)
06        canDoDmg = false
07        wait(1)
08        canDoDmg = true
09    end
10end)
11 
12connectionLeft = plr.Character.LeftHand.Touched:Connect(function(hit)
13    if hit.Parent.Humanoid and canDoDmg then
14        hit.Parent.Humanoid:TakeDamage(plr.Stats.Damage.Value)
15        canDoDmg = false
View all 23 lines...
0
Thank you so much , i learned a new thing from you called Disconnect(), more knowledge on the way :D Hate_ZEU 47 — 3y
0
quick note, you should disconnect the events outside of the function because the event wouldnt disconnect until it hits something and thats not what you want, I updated the script :3   mixgingengerina10 223 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

Scripting helpers is NOT a request site! Your question will soon be seen and deleted by a moderator. Please read the community guidelines: https://scriptinghelpers.org/help/community-guidelines

0
What do you mean, i didn`t request, i only asked what should i do to make this work, i even typed down i don`t want an entire script just an explanation Hate_ZEU 47 — 3y
0
This site is for solving errors lady JasiuJasiuB 13 — 3y
0
im a moderator and im banning you before him Xapelize 2658 — 3y
0
joke Xapelize 2658 — 3y
View all comments (2 more)
0
but he made his own script and thats weird he wanted explanation Xapelize 2658 — 3y
0
First of all jasiu don`t call me lady you don`t even know me, and xapelize i only asked for a help because i don`t know what to do to make it so it deals damage only when i use a certain key , my script deals damage when my hands touches the character even tho i don`t press on F and that`s what i want a fix for, don`t be toxic Hate_ZEU 47 — 3y

Answer this question