I am trying to make a system like Sword Fighting Simulator where you swing a sword and the NPC takes damage from how much Power you have.
I know the problem is getting the player leaderstats, but I don’t know how to do it correctly.
This script is in the Sword (Normal Script)
This is in a part of a part of the sword (Normal Script)
function onTouch(hit)
if hit.Parent:FindFirstChild('HealthSpot') then --Checks for HealthSpot in NPC
local Sound = script.SoundEffect
script.Disabled = true
Sound:play() --Sound of the swords hitting the NPC
local Effect = script.Parent.Effect
local humanoid = hit.Parent:FindFirstChild("Humanoid")
local animation = script.Animation
local animationtrack = humanoid.Animator:LoadAnimation(animation)
animationtrack:Play() --Makes NPC have a hit effect
game.Players:GetPlayerFromCharacter(hit.Parent) --Gets the player
local Power = hit.Parent.leaderstats.Power
humanoid = humanoid.Health - Power.Value --Damage taked to the NPC
Effect.Rate = 100 --The Partical Effet of the NPC getting hit
task.wait(0.5)
Effect.Rate = 0
end
end
script.Parent.Touched:Connect(onTouch)