How would I start if I wanted lets say a sword to effect another player when swung and that player that player takes damage when blade touches them?
✓ ANSWER ACCEPTED
Effect another player?
1 answer
✓ Accepted answer
Well, a simple way to get you started would be using a 'Touched' function.
--script.Parent would be the blade (a part). Thus this script goes inside of it. But you can easily change that if you'd like.
debounce = false --To ensure that the humanoid does not lose all of their health instantly, we'll use debounce to yeild damaging.
script.Parent.Touched:connect(function(hit)--Fires when the blade is touched, and hit is the part that touched the blade.
if debounce == true then return end --If debounce is true, then the function will not continue
debounce = true --If debounce was false, then it will continue and make debounce true.
if hit.Parent:FindFirstChild("Humanoid") then --Checks if the hit's parent contains a humanoid
hit.Parent.Humanoid:TakeDamage(10) --Subtracts 10 health points from the humanoid. Change 10 to your desired damage.
end --Ends if statement
wait(1) --Yeilds for 1 second --this is how long the script will wait untill the function will be able to fire again.
debounce = false --Now debounce is false, and the script can now fire again.
end) --Ends touched function
This is of course, one of the easiest functions to use for this sort of thing, and is good for beginners to use in order to progress.
I encourage you to build on to this script to your own liking, and learn on your own; we won't be able to provide for you all the time!
Hope this helped!
This discussion is preserved as it was. New answers, comments, and votes are closed.
