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

How do I now make this damage the player getting hit then remove itself?

Asked by 9 years ago

I want to make the beam that got shot out to damage the player it hit and also remove itself after it has damaged the player that it hit. Script:

player = game.Players.LocalPlayer
mouse = player:GetMouse()
mouse.KeyDown:connect(function(key)
        key = key:lower()
    if key == "e" then
for i = 0,0.5,.1 do
    wait()
RightShoulder = game.Workspace.Player.Torso["Right Shoulder"]
RightShoulder.C0 = RightShoulder.C0 * CFrame.fromEulerAnglesXYZ(0,-i,0)
end
for q = 0,0.5,.1 do
    wait()
RightShoulder.C0 = RightShoulder.C0 * CFrame.fromEulerAnglesXYZ(q,0,0)
end
wait()
for i = 0,0.5,.1 do
    RightShoulder.C0 = RightShoulder.C0 * CFrame.fromEulerAnglesXYZ(-i,0,0)
        wait()
end
for i = 0,0.5,.1 do
    RightShoulder.C0 = RightShoulder.C0 * CFrame.fromEulerAnglesXYZ(0,i,0)
        wait()
end
        for i = 3,45 do
            wait()
            earth = Instance.new("Part",workspace)
            earth.Size = Vector3.new(4,4,4)
            earth.Name = "Fire"
            earth.CanCollide = false
            earth.BrickColor = BrickColor.new("Bright red")
            earth.Anchored = true
            earth.CFrame = player.Character.Torso.CFrame * CFrame.new(0,0,-5+-i) * CFrame.fromEulerAnglesXYZ(math.random(),math.random(),math.random())
            player.Character.Torso.Anchored = true
            my = game.Lighting.Earth:Clone()
            my.Parent = earth
        end
        player.Character.Torso.Anchored = false
end
end)

1 answer

Log in to vote
0
Answered by
Marios2 360 Moderation Voter
8 years ago

In Roblox's Slingshot, there is a separate script to damage players that gets inserted to the bullet and gets enabled. --The More You Know--

So we're going to do the same here. Along with optimizing your original script and updating it to modern times, i also made it to insert a copy of the separate damaging script in your beam and enable said script. Make sure to disable the damage script at first!

Main script

player = game.Players.LocalPlayer
mouse = player:GetMouse()
mouse.KeyDown:connect(function(key)
        key = key:lower()
    if key == "e" then
local RightShoulder = game.Workspace.Player.Torso["Right Shoulder"] --You need more effeciency! I put RightShoulder over there and set it to local. It can be used anywhere inside this statement.
for i = 0,0.5,.1 do
    wait()
RightShoulder.C0 = RightShoulder.C0 * CFrame.fromEulerAnglesXYZ(0,-i,0)
end
for q = 0,0.5,.1 do
    wait()
RightShoulder.C0 = RightShoulder.C0 * CFrame.fromEulerAnglesXYZ(q,0,0)
end
wait()
for i = 0,0.5,.1 do
    RightShoulder.C0 = RightShoulder.C0 * CFrame.fromEulerAnglesXYZ(-i,0,0)
        wait()
end
for i = 0,0.5,.1 do
    RightShoulder.C0 = RightShoulder.C0 * CFrame.fromEulerAnglesXYZ(0,i,0)
        wait()
end
        for i = 3,45 do
            wait()
            local earth = Instance.new("Part",workspace) --You aren't using earth anywhere outside this statement, set it to local.
            earth.Size = Vector3.new(4,4,4)
            earth.Name = "Fire"
            earth.CanCollide = false
            earth.BrickColor = BrickColor.new("Bright red")
            earth.Anchored = true
            earth.CFrame = player.Character.Torso.CFrame * CFrame.new(0,0,-5+-i) * CFrame.fromEulerAnglesXYZ(math.random(),math.random(),math.random())
            player.Character.Torso.Anchored = true
            local my = game.ReplicatedStorage.Earth:Clone() --Move Earth to ReplicatedStorage, it was made just to replace Lighting. And set this to local too.
            my.Parent = earth
            local escript = script.Parent.BeamScript:Clone() --The separate damaging script to get inside the beam
            escript.Parent = earth
            escript.Disabled = false --The script must be disabled at first, lest the handle damages whoever it touches and removes itself
        end
        player.Character.Torso.Anchored = false
end
end)

Script inside earth

script.Parent.Touched:connect(function(part)
    if part.Parent:FindFirstChild("Humanoid") then 
        part.Parent:WaitForChild("Humanoid"):TakeDamage(damage) --Replace "damage" with the amount of damage you want to deal (it can be a double and larger than MaxHealth)
        script.Parent:Destroy() --Beam begone!
    end
end)
Ad

Answer this question