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

I'm trying to fix this KeyDown Ki Blast attack, can someone help me?

Asked by 9 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

The first part of the script is in a LocalScript called KiBlast:

Player = script.Parent.Parent
mouse = Player:GetMouse()
run = game:GetService("RunService")
function onKeyDown(key)
    script.Disabled = true
    Key = key:lower()
    if key == "q" then
        RightShoulder = Player.Character.Torso["Right Shoulder"]
        LeftShoulder = Player.Character.Torso["Left Shoulder"]
        Run = game:GetService("RunService")
        for i = 1,10 do
            LeftShoulder.C0 = LeftShoulder.C0 * CFrame.Angles(0,0,0.155)
            RightShoulder.C0 = RightShoulder.C0 * CFrame.Angles(0,0,0.155)
            Run.Stepped:wait(0.025)
        end
        x = Instance.new("Part")
        x.BrickColor = BrickColor.new("Pastel light blue")
        x.FormFactor = "Custom"
        x.Size = Vector3.new(2.4,2.4,2.4)
        x.TopSurface = "SmoothNoOutlines"
        x.BottomSurface = "SmoothNoOutlines"
        x.Shape = "Ball"
        x.Name = "ki"
        x.Transparency = 0.1
        kd = script.KiDamage:clone()
        kd.Parent = x
        y = Instance.new("BodyVelocity")
        y.maxForce = Vector3.new(math.huge, math.huge, math.huge)
        y.velocity = Player.Character["Right Arm"].CFrame.lookVector * 60
        x.Parent = workspace
        y.Parent = x
        light = Instance.new("PointLight")
        light.Parent = x
        light.Brightness = 100
        light.Color = Color3.new(170/255, 255/255, 255/255)
        light.Range = 8
        billboard = Instance.new("BillboardGui")
        billboard.Parent = x
        pic = Instance.new("ImageLabel")
        pic.Parent = billboard
        pic.BackgroundTransparency = 1
        pic.Image = "http://www.roblox.com/asset/?id=198656006"
        pic.ImageTransparency = 0.4
        pic.Size = UDim2.new(1, 0, 1, 0)
        pic.Name = "Light"
        pic.Visible = true
        x.CFrame = Player.Character["Right Arm"].CFrame * CFrame.new(0, -3, 0)
        kd.Disabled = false
        game.Debris:AddItem(x, 6)
        wait(0.25)
        for i = 1,10 do
            LeftShoulder.C0 = LeftShoulder.C0 * CFrame.Angles(0,0,-0.155)
            RightShoulder.C0 = RightShoulder.C0 * CFrame.Angles(0,0,-0.155)
            Run.Stepped:wait(0.025)
        end
    end
    script.Disabled = false
    wait(0.1)
end
mouse.KeyDown:connect(onKeyDown)

Part 2 is a Script called KiDamage that's inside the LocalScript KiBlast:

function onDamage(Part)
    if Part.Parent:FindFirstChild("Humanoid") ~= nil and Part.Parent.Name ~= "script.Parent.Name"
    then
        script.Disabled = true
        for i = 1, 25 do
            Part.Parent.Humanoid.Health = Part.Parent.Humanoid.Health - 1
            wait(0.05)
        end
        Part.Parent.Humanoid.PlatformStand = true
        script.Parent:remove()
    end
    wait(0.025)
end

script.Parent.Touched:connect(onDamage)

Whenever you press q, instead of going forward it goes up. Can someone tell me what's wrong with the code?

0
In your ki damage script you put quouts around script.Parent.Name in line 2. You don't have to do that, it will error. yoshiegg6 176 — 9y

2 answers

Log in to vote
0
Answered by
yoshiegg6 176
9 years ago

Warning: This answer isn't about a scripting error it's about efficiency.

You've devoted so many lines of code to moving your characters arm smoothly, but you can easily just play an animation in the character and use the keyframes reached event to shoot the ki blast when the arm goes out.

Also, I've noticed you're using instance to create your ki blast. No offense, but that's kind of a beginner game dev mistake. You can make your ki blast look 20x better and removing tons of code by creating and editing it in studio to make sure it looks perfect, maybe add some lights, edit those and then put the finished product, the ki blast in replicated storage. Whenever you need it replace this eyesore:

x = Instance.new("Part")
x.BrickColor = BrickColor.new("Pastel light blue")
x.FormFactor = "Custom"
x.Size = Vector3.new(2.4,2.4,2.4)
x.TopSurface = "SmoothNoOutlines"
x.BottomSurface = "SmoothNoOutlines"
x.Shape = "Ball"
x.Name = "ki"

with this

x = game.ReplicatedStorage.kiblast:Clone().Parent = workspace

Boom easy as cake

Do the same with the image label and anything else you instance.

0
Thank you so much, that'll really help me in the future. ZaltherusKenobi 15 — 9y
0
No problem man. yoshiegg6 176 — 9y
Ad
Log in to vote
1
Answered by
neoG457 315 Moderation Voter
9 years ago

It goes wrong because

 y = Instance.new("BodyVelocity")
 y.maxForce = Vector3.new(math.huge, math.huge, math.huge)
 y.velocity = Player.Character["Right Arm"].CFrame.lookVector * 60

The movement of your arms animation makes it fire up.

 y = Instance.new("BodyVelocity")
 y.maxForce = Vector3.new(math.huge, math.huge, math.huge)
 y.velocity = Player.Character.Torso.CFrame.lookVector * 60

Firing from the torso should make it fire straight.

0
Tell me if it doesnt work and I'll try again. neoG457 315 — 9y
0
It fixed it. ZaltherusKenobi 15 — 9y
0
Real script; ILocheGameplayYT 0 — 4y

Answer this question