This is my script. I want it to only damage once for a certain amount of time, also play an animation on click. However, in pvp, it needs to be in server script for it to reflect to players, how would I get the mouse1input? Script:
--need to add animation and cooldown--
damage = script.Parent.itemDamage.Value
sword = script.Parent.Handle
Tool = script.Parent
function getPlayerDamage(humanoid, vPlayer, enemyPlayer) -- gets the damage to the player in pvp in relation to stats
local hitChance = math.random(1,500)
if hitChance > (500-enemyPlayer.Stats.Dexterity.Value) then -- hits or misses based on evasion
local firstDamage = damage*(1+(vPlayer.Stats.Strength.Value/100))
local damageReduction = (firstDamage)*(enemyPlayer.Stats.Defense.Value/500)
local finalDamage = firstDamage - damageReduction
humanoid:TakeDamage(finalDamage)
else
print("missed")
end
end
function blow(hit)
if hit.Parent:findFirstChild("Monster") then
local humanoid = hit.Parent:findFirstChild("Monster")
local vCharacter = Tool.Parent
local vPlayer = game.Players:playerFromCharacter(vCharacter)
local hum = vCharacter:findFirstChild("Humanoid") -- non-nil if tool held by a character
if humanoid~=nil and humanoid ~= hum and hum ~= nil then
print("SWORD HIT MONSTER")
tagHumanoid(humanoid, vPlayer)
humanoid:TakeDamage(damage)
wait(1)
untagHumanoid(humanoid)
end
elseif hit.Parent:findFirstChild("Humanoid") then
local humanoid = hit.Parent:findFirstChild("Humanoid") -- Attacked player's humanoid
local vCharacter = Tool.Parent
local vPlayer = game.Players:playerFromCharacter(vCharacter) -- Attacking player
local enemyCharacter = humanoid.Parent
local enemyPlayer = game.Players:playerFromCharacter(enemyCharacter) -- Enemy player
local hum = vCharacter:findFirstChild("Humanoid") -- Attacking player's humanoid
if humanoid~=nil and humanoid ~= hum and hum ~= nil then
print("SWORD HIT PLAYER")
tagHumanoid(humanoid, vPlayer)
getPlayerDamage(humanoid, vPlayer, enemyPlayer)
wait(1)
untagHumanoid(humanoid)
end
else
print("break")
end
end
function tagHumanoid(humanoid, player)
if humanoid:findFirstChild("creator") then -- prevents overlapping
if humanoid.creator.Value == player then
humanoid.creator:Destroy()
end
end
local creator_tag = Instance.new("ObjectValue")
creator_tag.Value = player
creator_tag.Name = "creator"
creator_tag.Parent = humanoid
end
function untagHumanoid(humanoid)
wait(10) -- Destroys creator after how many seconds
if humanoid ~= nil then
local tag = humanoid:findFirstChild("creator")
if tag ~= nil then
tag.Parent = nil
end
end
end
Mouse.Button1Down:Connect(blow)
connection = sword.Touched:Connect(blow)
It's not free model at all, aside from the tagging reference used in linked swords, everything else was written by me (and commented because commenting is important)
But I got the answer, you could just use tool.activated

1 comment
Don't come on this site with free model code, expecting for it to be fixed.