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

Sword Mouse Click Damage Debounce Issues [?]

Asked by 6 years ago
Edited 6 years ago

Goal:

My goal is to simply create a Sword that will play an animation and deal damage on click. I want the damage to ONLY deal damage when the animation is playing and touched the enemy.

Problem:

Everything works fine except the damaging part. So say an enemy is 100 studs away if I click once and then run up to the enemy and the sword touches the enemy without me clicking again it will deal damage. the system basically stores it as this player has clicked so I can now deal damage which isn't what I want. I want the player to click, play the animation and during the animation playing if sword touches enemy it deals damage.

Code:

01--// Normal Vars \\--
02local plr = game.Players.LocalPlayer
03local Char = plr.Character or plr.CharacterAdded:Wait()
04local Humanoid = Char.Humanoid
05local Mouse = plr:GetMouse()
06 
07local EquippedItems = plr:WaitForChild('EquippedItems')
08local Weapons = plr:WaitForChild('Weapons')
09local PlayerStatus = plr:WaitForChild('PlayerStatus')
10 
11--// Services \\--
12local ReplicatedStorage = game:GetService("ReplicatedStorage")
13local UIS = game:GetService("UserInputService")
14 
15--// Settings \\--
View all 62 lines...

This is only part of my code. note that this is a LocalScript

Server Script:

1local SerDmgD = true
2RE.DamageEvent.OnServerEvent:Connect(function(plr, Dmg, Enemy, Wep)
3    if Dmg == ItemInformation[Wep].Damage and SerDmgD then
4        SerDmgD = false
5        Enemy:TakeDamage(Dmg)
6        wait(0.6)
7        SerDmgD = true
8    end
9end)

My other part is a UserInputService and welds the Sword to the player.

I appreciate any feedback that will help Solve the problem.

0
How else would I manage Touch, and how else would I said ~= nil BlackOrange3343 2676 — 6y
0
Handle the touching part in the serverscript as incapaz said and make another script which will damage another player on contact and make it disabled by default, then everytime the player clicks you enable the damage script for the duration of the animation (i.e if the animation is 2 seconds long enable it for 2 seconds and then disable it so the touch event doesn't get fired afterwards.) FIamezR 15 — 6y
0
Try putting the Damage code in a KeyframeReached event and assign a Keyframe name in the editor. Here is some more information. https://wiki.roblox.com/index.php?title=API:Class/AnimationTrack/KeyframeReached Alvin_Blox 52 — 6y

Answer this question