Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make this punch script use magnitude insetad of look vector?

Asked by 4 years ago
Edited 4 years ago

I want to make this to where the people around can get hit instead of the people you are looking at. The Local Script is placed in starterpack. In the local script is a remote event and in the remote event is the server script. In the server script are the animations and sound

---Server Script
local Cooldown = false
local Combo = 0
local Delay = .35
local BasicAttack = 5 
local FinalCombo = 10
local TimeToAttack = .8 
local WSDBF = 0
local Delayersp = .1 

script.Parent.OnServerEvent:Connect(function(Player, Stunned)
if Stunned.Value == true then return end    
Combo = Combo + 1 

local SwingFist = Instance.new("Sound")
SwingFist.SoundId = "http://www.roblox.com/asset/?id=28166555"
SwingFist.MaxDistance = 100 
SwingFist.Parent = Player.Character.HumanoidRootPart
game.Debris:AddItem(SwingFist,.5)

if Combo == 1 then  

local rightPunch = Player.Character.Humanoid:LoadAnimation(script.rightPunch)
rightPunch:Play() 
SwingFist:Play()

local ray = Ray.new(Player.Character.HumanoidRootPart.Position, Player.Character.HumanoidRootPart.CFrame.lookVector * 8)
local hit = workspace:FindPartOnRay(ray, Player.Character)

if hit and hit.Parent:FindFirstChild("Humanoid") then 

    hit.Parent.Humanoid:TakeDamage(BasicAttack)

    local Punched1 = script.Punched1:Clone()
    Punched1.Parent = hit.Parent.HumanoidRootPart
    Punched1:Play()
    game.Debris:AddItem(Punched1,.5)
    local track = hit.Parent.Humanoid:LoadAnimation(script.PunchedLeft)
    track:Play()
    local BodyVelocity = Instance.new("BodyVelocity",Player.Character.HumanoidRootPart)
    BodyVelocity.Velocity = Player.Character.HumanoidRootPart.CFrame.lookVector * 10
    BodyVelocity.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
    game.Debris:AddItem(BodyVelocity,.1)
    local NormalHit = game.ReplicatedStorage.NormalHit:Clone()
    NormalHit.Parent = workspace
    local Weld = Instance.new("Weld",NormalHit)
    Weld.Part0 = NormalHit
    Weld.Part1 = hit.Parent.Head
    Weld.C1 = CFrame.new(0,0,-1)
    game.Debris:AddItem(NormalHit,.3)
    hit.Parent.Humanoid.WalkSpeed = hit.Parent.Humanoid.WalkSpeed - WSDBF

    spawn(function()
        wait(Delay+Delayersp)
        hit.Parent.Humaoid.WalkSpeed = hit.Parent.HumanoidWalkSpeed + WSDBF
    end)

end





spawn(function()
    wait(TimeToAttack)
    if Combo == 2 then 
    else  
        Combo = 0 
    end
end)


else if Combo == 2 then 

spawn(function()
    wait(TimeToAttack)
    if Combo == 3 then 
    else  
        Combo = 0 
    end
end)

local leftPunch = Player.Character.Humanoid:LoadAnimation(script.leftPunch)
leftPunch:Play() 
SwingFist:Play()

local ray = Ray.new(Player.Character.HumanoidRootPart.Position, Player.Character.HumanoidRootPart.CFrame.lookVector * 8)
local hit = workspace:FindPartOnRay(ray, Player.Character)

if hit and hit.Parent:FindFirstChild("Humanoid") then 
    hit.Parent.Humanoid:TakeDamage(BasicAttack)

    local Punched2 = script.Punched2:Clone()
    Punched2.Parent = hit.Parent.HumanoidRootPart
    Punched2:Play()
    game.Debris:AddItem(Punched2,.5)
    local track = hit.Parent.Humanoid:LoadAnimation(script.PunchedRight)
    track:Play()
    local BodyVelocity = Instance.new("BodyVelocity",Player.Character.HumanoidRootPart)
    BodyVelocity.Velocity = Player.Character.HumanoidRootPart.CFrame.lookVector * 10
    BodyVelocity.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
    game.Debris:AddItem(BodyVelocity,.1)
        local NormalHit = game.ReplicatedStorage.NormalHit:Clone()
    NormalHit.Parent = workspace
    local Weld = Instance.new("Weld",NormalHit)
    Weld.Part0 = NormalHit
    Weld.Part1 = hit.Parent.Head
    Weld.C1 = CFrame.new(0,0,-1)
    game.Debris:AddItem(NormalHit,.3)

        hit.Parent.Humanoid.WalkSpeed = hit.Parent.Humanoid.WalkSpeed - WSDBF

    spawn(function()
        wait(Delay+Delayersp)
        hit.Parent.Humaoid.WalkSpeed = hit.Parent.HumanoidWalkSpeed + WSDBF
    end)

end


else if Combo == 3 then 

local rightUpperCut = Player.Character.Humanoid:LoadAnimation(script.rightUpperCut)
rightUpperCut:Play()
SwingFist:Play()

spawn(function()
    wait(TimeToAttack)
    if Combo == 4 then 
    else  
        Combo = 0 
    end
    local RightArm = false
end)

local ray = Ray.new(Player.Character.HumanoidRootPart.Position, Player.Character.HumanoidRootPart.CFrame.lookVector * 8)
local hit = workspace:FindPartOnRay(ray, Player.Character)

if hit and hit.Parent:FindFirstChild("Humanoid") then 

    hit.Parent.Humanoid:TakeDamage(BasicAttack)

    local Punched3 = script.Punched3:Clone()
    Punched3.Parent = hit.Parent.HumanoidRootPart
    Punched3:Play()
    game.Debris:AddItem(Punched3,.5)
    local track = hit.Parent.Humanoid:LoadAnimation(script.leftUpperCutPunch)
    track:Play()
    local BodyVelocity = Instance.new("BodyVelocity",Player.Character.HumanoidRootPart)
    BodyVelocity.Velocity = Player.Character.HumanoidRootPart.CFrame.lookVector * 10
    BodyVelocity.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
    game.Debris:AddItem(BodyVelocity,.1)
        local NormalHit = game.ReplicatedStorage.NormalHit:Clone()
    NormalHit.Parent = workspace
    local Weld = Instance.new("Weld",NormalHit)
    Weld.Part0 = NormalHit
    Weld.Part1 = hit.Parent.Head
    Weld.C1 = CFrame.new(0,0,-1)
    game.Debris:AddItem(NormalHit,.3)

        hit.Parent.Humanoid.WalkSpeed = hit.Parent.Humanoid.WalkSpeed - WSDBF

    spawn(function()
        wait(Delay+Delayersp)
        hit.Parent.Humaoid.WalkSpeed = hit.Parent.HumanoidWalkSpeed + WSDBF
    end)

end


else if Combo == 4 then 

local leftUpperCut = Player.Character.Humanoid:LoadAnimation(script.leftUpperCut)
leftUpperCut:Play()
SwingFist:Play()

spawn(function()
    wait(TimeToAttack)
    if Combo == 5 then 
    else  
        Combo = 0 
    end
    local RightArm = false
end)


local ray = Ray.new(Player.Character.HumanoidRootPart.Position, Player.Character.HumanoidRootPart.CFrame.lookVector * 8)
local hit = workspace:FindPartOnRay(ray, Player.Character)

if hit and hit.Parent:FindFirstChild("Humanoid") then 

    hit.Parent.Humanoid:TakeDamage(BasicAttack)

    local Punched4 = script.Punched4:Clone()
    Punched4.Parent = hit.Parent.HumanoidRootPart
    Punched4:Play()
    game.Debris:AddItem(Punched4,.5)
    local track = hit.Parent.Humanoid:LoadAnimation(script.rightUpperCutFace)
    track:Play()
        local Punched4 = script.Punched4:Clone()
    Punched4.Parent = hit.Parent.HumanoidRootPart
    Punched4:Play()
    local BodyVelocity = Instance.new("BodyVelocity",Player.Character.HumanoidRootPart)
BodyVelocity.Velocity = Player.Character.HumanoidRootPart.CFrame.lookVector * 10
BodyVelocity.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
game.Debris:AddItem(BodyVelocity,.1)
    local NormalHit = game.ReplicatedStorage.NormalHit:Clone()
    NormalHit.Parent = workspace
    local Weld = Instance.new("Weld",NormalHit)
    Weld.Part0 = NormalHit
    Weld.Part1 = hit.Parent.Head
    Weld.C1 = CFrame.new(0,0,-1)
    game.Debris:AddItem(NormalHit,.3)

        hit.Parent.Humanoid.WalkSpeed = hit.Parent.Humanoid.WalkSpeed - WSDBF

    spawn(function()
        wait(Delay+Delayersp)
        hit.Parent.Humaoid.WalkSpeed = hit.Parent.HumanoidWalkSpeed + WSDBF
    end)

end

else if Combo == 5 then

local Kick = Player.Character.Humanoid:LoadAnimation(script.Kick)
Kick:Play()
SwingFist:Play()

local ray = Ray.new(Player.Character.HumanoidRootPart.Position, Player.Character.HumanoidRootPart.CFrame.lookVector * 8)
local hit = workspace:FindPartOnRay(ray, Player.Character)

if hit and hit.Parent:FindFirstChild("Humanoid") then 

    hit.Parent.Humanoid:TakeDamage(FinalCombo)

    local track = hit.Parent.Humanoid:LoadAnimation(script.kickFace)
    track:Play()
            local Punched5 = script.Final:Clone()
    Punched5.Parent = hit.Parent.HumanoidRootPart
    Punched5:Play()
    local BodyVelocity = Instance.new("BodyVelocity",hit.Parent.HumanoidRootPart)
        BodyVelocity.Velocity = hit.Parent.HumanoidRootPart.CFrame.lookVector * -50
        BodyVelocity.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
        game.Debris:AddItem(BodyVelocity,.6)
        local BodyVelocity = Instance.new("BodyVelocity",Player.Character.HumanoidRootPart)
BodyVelocity.Velocity = Player.Character.HumanoidRootPart.CFrame.lookVector * 10
BodyVelocity.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
game.Debris:AddItem(BodyVelocity,.1)
local NormalHit = game.ReplicatedStorage.NormalHit:Clone()
    NormalHit.Parent = workspace
    local Weld = Instance.new("Weld",NormalHit)
    Weld.Part0 = NormalHit
    Weld.Part1 = hit.Parent.Head
    Weld.C1 = CFrame.new(0,0,-1)
    game.Debris:AddItem(NormalHit,.3)

    hit.Parent.Humanoid.WalkSpeed = hit.Parent.Humanoid.WalkSpeed - WSDBF

    spawn(function()
        wait(Delay+Delayersp)
        hit.Parent.Humaoid.WalkSpeed = hit.Parent.HumanoidWalkSpeed + WSDBF
    end)

end


Combo = 0   




                end
            end         
        end 
    end
end






















end)

--Local Script

wait(2)

local Cooldown = false
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Stunned = Character.Stunned
local Mouse = Player:GetMouse()
local Delay = .35

Mouse.Button1Down:Connect(function()
if Stunned.Value == true then return end 
if Cooldown then return end 
for _, v in pairs(Player.Character:GetChildren()) do
if v:IsA("Tool") then return end
end 

spawn(function()
    Cooldown = true
    wait(Delay)
    Cooldown = false 
end)

script.RemoteEvent:FireServer(Stunned)  


local ray = Ray.new(Player.Character.HumanoidRootPart.Position, Player.Character.HumanoidRootPart.CFrame.lookVector * 8)
local hit = workspace:FindPartOnRay(ray, Player.Character)

hit.Parent.Stunned.Value = true

spawn(function()
    wait(Delay+6)
    hit.Parent.Stunned.Value = false 
end)


end)

1 answer

Log in to vote
0
Answered by 4 years ago

To use magnitude you will need to run a for loop each time checking each players range. Anyone within range gets damaged.

Here's a bit of an example:


local plr = game.Players.YourPlayer local range = 5 local damage = 10 function damageHum(hum) hum:TakeDamage(damage) end for _,v in pairs(game.Players:GetPlayers()) do if plr.Character and v.Character then local root1 = plr.Character:FindFirstChild("HumanoidRootPart") local root2 = v.Character:FindFirstChild("HumanoidRootPart") if root1 and root2 and (root1.Position - root2.Position).magnitude <= range then if v.Character:FindFirstChild("Humanoid") then damageHum(v.Character.Humanoid) end end end end
0
How would this look like in the script above? Justingamer700 114 — 4y
Ad

Answer this question