I’m trying to make a sword for my game but it ends up instakilling anything to touches for some reason.
This is my script.
--variables--
box = script.Parent
tool = box.Parent
cooldown = tool.Cooldown.Value
damage = tool.Damage.Value
debounce = false
yourchar = tool.Parent
yourplr = game:GetService("Players"):GetPlayerFromCharacter(yourchar)
dmgeffect = game.ReplicatedStorage.DamageHighlight
--script--
box.Touched:Connect(function(hit)
if debounce == false then
debounce = true
--find the character box touched
local char = hit.Parent
--find the player of the character
local player = game.Players:GetPlayerFromCharacter(char)
local def = char.Humanoid.DefenseValue.Value/100
local totaldmg = damage * tool.Parent.Humanoid.AttackValue.Value / def
--damage the player
if player then
if player.TeamColor == yourplr.TeamColor then
else
player.Character.Humanoid.Health = player.Character.Humanoid.Health - totaldmg
dmgclone = dmgeffect:Clone()
dmgclone.Parent = char
dmgclone.Script.Enabled = true
--if the player they hit died, increase yourplr.leaderstats.Kills by 1
if player.Character.Humanoid.Health <= 0 then
yourplr.leaderstats.Kills.Value = yourplr.leaderstats.Kills.Value + 1
yourplr.leaderstats.Streak.Value = yourplr.leaderstats.Streak.Value + 1
end
end
elseif not player then
char.Humanoid.Health = char.Humanoid.Health - totaldmg
dmgclone = dmgeffect:Clone()
dmgclone.Parent = char
dmgclone.Script.Enabled = true
if char.Humanoid.Health <= 0 then
yourplr.leaderstats.Kills.Value = yourplr.leaderstats.Kills.Value + 1
yourplr.leaderstats.Streak.Value = yourplr.leaderstats.Streak.Value + 1
end
end
wait(cooldown)
debounce = false
end
end)
I had the video’s damage as 1 because i was testing to see if there was some multiplier that i added by accident.