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

[Read Below] - Attempted to make a level requirement for killing a certain mob. Can anyone Help?

Asked by 6 years ago
Edited 6 years ago

So what i'm trying to do is make it where you have to be a certain level to get the Experience/Money from the mob. This is going to prevent exploiters from grinding in high level areas because they have to be to a certain level to gain the Experience/Money.

local Humanoid = script.Parent.Humanoid

function PwntX_X()
    local tag = Humanoid:FindFirstChild("creator")
    if tag ~= nil then
            local Leaderstats = tag.Value:FindFirstChild("leaderstats")
            local lvl = Leaderstats:FindFirstChild("Level")
            if lvl == 15 then
            if Leaderstats ~= nil then
                Leaderstats.Experience.Value = Leaderstats.Experience.Value + 25
                wait(0.1)
                script:Remove()
                end
            end
        end
    end
end

Humanoid.Died:Connect(PwntX_X)

local Humanoid = script.Parent.Humanoid

function PwntX_X()
    local tag = Humanoid:FindFirstChild("creator")
    if tag ~= nil then
        if tag.Value ~= nil then
            local Leaderstats = tag.Value:FindFirstChild("leaderstats")
            local lvl = Leaderstats:FindFirstChild("Level")
            if lvl == 15 then
            if Leaderstats ~= nil then
                Leaderstats.Money.Value = Leaderstats.Money.Value + 25
                wait(0.1)
                script:Remove()
                end
            end
        end
    end
end

Humanoid.Died:Connect(PwntX_X)
1
You need to tell us what is going wrong with your script in order for us to help. Errors? Unexpected behavior? lukeb50 631 — 6y
0
No errors >_> Sorry for the late response. TheForgottenTale 23 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

You did the same function twice. I don't know why you did that I also changed the function name to a more appropriate name because when you come back to the script you might not understand it

local Humanoid = script.Parent.Humanoid

local function enemyDied()
    local tag = Humanoid:FindFirstChild("creator")
    if tag ~= nil then
            local Leaderstats = tag:FindFirstChild("leaderstats")
            local lvl = Leaderstats:FindFirstChild("Level")
            if lvl >= 15 then -- You just checked if the level is exactly 15 but what if you're over level 15??
            if Leaderstats ~= nil then
                Leaderstats.Experience.Value = Leaderstats.Experience.Value + 25
                -- You were just removing the script.Why do this if you need it again
                end
            end
    end
end
Humanoid.Died:Connect(enemyDied)

If this answer helped you or help you find your problem then Please submit this answer

0
I got the error: --> Workspace.Test.Experience:7: attempt to index local 'Leaderstats' (a nil value) TheForgottenTale 23 — 6y
0
I got it to work thank you so much! TheForgottenTale 23 — 6y
0
Your welcome saSlol2436 716 — 6y
Ad

Answer this question