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

How to add EXP into a OnKeyPressed script?

Asked by 9 years ago

I have been trying to use an EXP script that I have but the problem was I couldn't add it to my existing tool so that every time the tool is used, it would give the person who used it EXP. This is the main script to gain EXP when a NPC is "killed":

function onHealthChanged() 
    local zHuman =  script.Parent:findFirstChild( "Humanoid" )
    if zHuman ~= nil then 
        local tag = zHuman:findFirstChild( "creator" ) 
        if tag ~= nil then 
            if tag.Value ~= nil then 
                local stats = tag.Value:findFirstChild("supercool") 
                if stats ~= nil then 
                    if tag.Value.Character ~= nil then 
                        stats.XP.Value = stats.XP.Value + 20 -- Edit for a custom amount of XP added
                    end
                end
            end 
        end 
    end

end 

I just need help in how to put this into any of my scripts, but mainly this part of my script:

if key == "z" then
    Deduction = 49.1
    if Player.Chakra.Value >= Deduction then
        Player.Chakra.Value = Player.Chakra.Value - Deduction
        game:GetService("Chat"):Chat(Player.Character.Head, "Flying Thunder God Technique")
        RightShoulder = Player.Character.Torso["Right Shoulder"]
        LeftShoulder =  Player.Character.Torso["Left Shoulder"]
        for i = 1, 2 do
            RightShoulder.C0 = RightShoulder.C0 * CFrame.Angles(0, 0.8, 0)
            wait()
        end
        x = game.Lighting.FlashKunai:clone()
        x.Parent = game.Workspace
        x.CFrame = Player.Character.Torso.CFrame * CFrame.new(0, 0, -1)
        x.Name = Player.Character.Name
        if Tool.Special.Value == 0 then
            x.Slash.Disabled = false
        elseif Tool.Special.Value == 1 then
            x.Slash2.Disabled = false
        end
        Path = Instance.new("BodyVelocity")
        Path.Parent = x
        Path.maxForce = Vector3.new(math.huge, math.huge, math.huge)
        Path.velocity = Player.Character.Torso.CFrame.lookVector * 225
        wait(0.3)
        F = x.Fire:clone()
        F.Parent = Player.Character.Torso
        F.Size = 15
        F.Heat = 25
        F.Enabled = true
        wait(0.1)
        Player.Character:MoveTo(x.Position + Vector3.new(0, 2, 0))
        F:Destroy()
        x:Destroy()
        for i = 1, 2 do
            RightShoulder.C0 = RightShoulder.C0 * CFrame.Angles(0, -0.8, 0)
            wait()
        end
    end
end

Just in case I included the beginning of the script down here for reference: Beginning

enabled = true
function onKeyDown(key) 
if not enabled then return end
enabled = false
local Tool = script.Parent
local Player = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
key = key:lower()

It would be a great help of commenting some ways of adding it or even answering it! Thanks for reading!

0
Tab this correctly please! Validark 1580 — 9y

1 answer

Log in to vote
1
Answered by
Validark 1580 Snack Break Moderation Voter
9 years ago

I tabbed it for you!

if key == "z" then
    Deduction = 49.1
    if Player.Chakra.Value >= Deduction then
        Player.Chakra.Value = Player.Chakra.Value - Deduction
        game:GetService("Chat"):Chat(Player.Character.Head, "Flying Thunder God Technique")
        RightShoulder = Player.Character.Torso["Right Shoulder"]
        LeftShoulder =  Player.Character.Torso["Left Shoulder"]
        for i = 1, 2 do
            RightShoulder.C0 = RightShoulder.C0 * CFrame.Angles(0, 0.8, 0)
            wait()
        end
        x = game.Lighting.FlashKunai:clone()
        x.Parent = game.Workspace
        x.CFrame = Player.Character.Torso.CFrame * CFrame.new(0, 0, -1)
        x.Name = Player.Character.Name
        if Tool.Special.Value == 0 then
            x.Slash.Disabled = false
        elseif Tool.Special.Value == 1 then
            x.Slash2.Disabled = false
        end
        Path = Instance.new("BodyVelocity")
        Path.Parent = x
        Path.maxForce = Vector3.new(math.huge, math.huge, math.huge)
        Path.velocity = Player.Character.Torso.CFrame.lookVector * 225
        wait(0.3)
        F = x.Fire:clone()
        F.Parent = Player.Character.Torso
        F.Size = 15
        F.Heat = 25
        F.Enabled = true
        wait(0.1)
        Player.Character:MoveTo(x.Position + Vector3.new(0, 2, 0))
        F:Destroy()
        x:Destroy()
        for i = 1, 2 do
            RightShoulder.C0 = RightShoulder.C0 * CFrame.Angles(0, -0.8, 0)
            wait()
        end
    end
end
0
Lol thanks Ninjaruaz 22 — 9y
Ad

Answer this question