Ad
Log in to vote
0

how do i make my weapon hurt only npcs and not players and make it work in R15?

Asked by 5 days ago

Tool = script.Parent Handle = Tool:WaitForChild("Handle")

Sparkles1 = Handle:WaitForChild("Sparkles1") Sparkles2 = Handle:WaitForChild("Sparkles2") Light1 = Handle:WaitForChild("Light1") Light2 = Handle:WaitForChild("Light2")

Players = game:GetService("Players") Debris = game:GetService("Debris") RunService = game:GetService("RunService")

DamageValues = { BaseDamage = 60, SlashDamage = 300, LungeDamage = 502 }

NormalSpeed = 32 RegularSpeed = (NormalSpeed + 2)

Damage = DamageValues.BaseDamage

Grips = { Up = CFrame.new(0, 0, -1.70000005, 0, 0, 1, 1, 0, 0, 0, 1, 0), Out = CFrame.new(0, 0, -1.70000005, 0, 1, 0, 1, -0, 0, 0, 0, -1) }

Sounds = { Slash = Handle:WaitForChild("SwordSlash"), Lunge = Handle:WaitForChild("SwordLunge"), Unsheath = Handle:WaitForChild("Unsheath") }

ToolEquipped = false

Tool.Grip = Grips.Up Tool.Enabled = true

function IsTeamMate(Player1, Player2) return (Player1 and Player2 and not Player1.Neutral and not Player2.Neutral and Player1.TeamColor == Player2.TeamColor) end

function TagHumanoid(humanoid, player) local Creator_Tag = Instance.new("ObjectValue") Creator_Tag.Name = "creator" Creator_Tag.Value = player Debris:AddItem(Creator_Tag, 2) Creator_Tag.Parent = humanoid end

function UntagHumanoid(humanoid) for i, v in pairs(humanoid:GetChildren()) do if v:IsA("ObjectValue") and v.Name == "creator" then v:Destroy() end end end

function Blow(Hit) if not Hit or not Hit.Parent or not CheckIfAlive() or not ToolEquipped then return end local RightArm = Character:FindFirstChild("Right Arm") if not RightArm then return end local RightGrip = RightArm:FindFirstChild("RightGrip") if not RightGrip or (RightGrip.Part0 ~= Handle and RightGrip.Part1 ~= Handle) then return end local character = Hit.Parent if character == Character then return end local humanoid = character:FindFirstChild("Humanoid") if not humanoid or humanoid.Health == 0 then return end local player = Players:GetPlayerFromCharacter(character) if player and (player == Player or IsTeamMate(Player, player)) then return end UntagHumanoid(humanoid) TagHumanoid(humanoid, Player) humanoid:TakeDamage(Damage) end

function Attack() Damage = DamageValues.SlashDamage Sounds.Slash:Play() local Anim = Instance.new("StringValue") Anim.Name = "toolanim" Anim.Value = "Slash" Anim.Parent = Tool end

function Lunge() Damage = DamageValues.LungeDamage

Sounds.Lunge:Play()

if ToolUnequipped then
    ToolUnequipped:disconnect()
end

local CurrentlyEquipped = true

ToolUnequipped = Tool.Unequipped:connect(function()
    CurrentlyEquipped = false
end)

local Anim = Instance.new("StringValue")
Anim.Name = "toolanim"
Anim.Value = "Lunge"
Anim.Parent = Tool

if CheckIfAlive() then
    Humanoid.WalkSpeed = (NormalSpeed + 100)
    local Force = Instance.new("BodyVelocity")
    Force.velocity = Vector3.new(0, 10, 0) 
    Force.maxForce = Vector3.new(0, 4000, 0)
    Debris:AddItem(Force, 0.4)
    Force.Parent = Torso
end

wait(0.2)
Tool.Grip = Grips.Out
wait(0.6)
Tool.Grip = Grips.Up

if ToolUnequipped then
    ToolUnequipped:disconnect()
end

if CurrentlyEquipped and CheckIfAlive() then
    Humanoid.WalkSpeed = RegularSpeed
end

Damage = DamageValues.SlashDamage

end

Tool.Enabled = true LastAttack = 0

function Activated()

if not Tool.Enabled or not ToolEquipped or not CheckIfAlive() then
    return
end

Tool.Enabled = false

Tick = RunService.Stepped:wait()

if (Tick - LastAttack < 0.2) then
    Lunge()
else
    Attack()
end

LastAttack = Tick

--wait(0.5)

Tool.Enabled = true

end

function CheckIfAlive() return (((Player and Player.Parent and Character and Character.Parent and Humanoid and Humanoid.Parent and Humanoid.Health > 0 and Torso and Torso.Parent) and true) or false) end

function Equipped() Character = Tool.Parent Player = Players:GetPlayerFromCharacter(Character) Humanoid = Character:FindFirstChild("Humanoid") Torso = Character:FindFirstChild("Torso") if not CheckIfAlive() then return end ToolEquipped = true Humanoid.WalkSpeed = RegularSpeed Sounds.Unsheath:Play() end

function Unequipped() Tool.Grip = Grips.Up if CheckIfAlive() then Humanoid.WalkSpeed = NormalSpeed end ToolEquipped = false end

Tool.Activated:connect(Activated) Tool.Equipped:connect(Equipped) Tool.Unequipped:connect(Unequipped)

Connection = Handle.Touched:connect(Blow)

function SetSparkles(Table) for i, v in pairs(Table) do if v and v.Sparkles and v.Sparkles.Parent then local SparkleColor = ((v.Sparkles == Sparkles1 and (((v.Color and v.Color) or Color3.new(math.random(-5, 5), math.random(-10, 12), math.random(0, 15)))) or (v.Sparkles == Sparkles2 and ((v.Color and v.Color) or Color3.new(math.random(-21, 12), math.random(-2, 3), math.random(-20, 15)))))) v.Sparkles.SparkleColor = SparkleColor if v.Light and v.Light.Parent then v.Light.Color = SparkleColor end end end end

Spawn(function() SetSparkles({{Sparkles = Sparkles1, Light = Light1, Color = Color3.new(1, 1, 1)}, {Sparkles = Sparkles2, Light = Light2, Color = Color3.new(1, 0, 1)}}) while true do wait(3) SetSparkles({{Sparkles = Sparkles1, Light = Light1}, {Sparkles = Sparkles2, Light = Light2}}) end end) i want to make this weapon work in r15 but idk how Also btw this is the epic katana and not some normal sword

0
Change "Right Arm" to RightUpperArm or RightHand AnasBahauddin1978 603 — 5d

1 answer

Log in to vote
0
Answered by 5 days ago
Edited 5 days ago

You didn't format your code correctly but I think I can still help. Do you see this part in the script with a lot of if statements that return early if they are true?

    if not RightGrip or (RightGrip.Part0 ~= Handle and RightGrip.Part1 ~= Handle) then
        return
    end
    local character = Hit.Parent
    if character == Character then
        return
    end
    local humanoid = character:FindFirstChildOfClass("Humanoid")
    if not humanoid or humanoid.Health == 0 then
        return
    end
    local player = Players:GetPlayerFromCharacter(character)
    if player and (player == Player or IsTeamMate(Player, player)) then
        return
    end

This part of the code makes sure that the player it's about to damage isn't the player that's holding it, or a teammate, as well as some other checks. We can check if the player is any player, and cancel the damage, in this way as well.

First, add this above the Blow() function:

function IsPlayer(character)
    return Players:GetPlayerFromCharacter(character)
end

Then add this to the code I showed you before:

if IsPlayer(character) then -- pass in the character as a parameter and cancel the damage if it matches to a player in the game (this will be nil if it is an NPC so the sword will deal damage)
    return
end

as for working in R15, I assume you mean the animations are broke or something? in that case, you'll have to remake the animations using an R15 rig

0
i mean the weapon literally doesn't work on R15 dylancrazy88 10 — 5d
Ad

Answer this question