Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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)

2 comments

1

You need to tell us what is going wrong with your script in order for us to help. Errors? Unexpected behavior?

0

No errors >_> Sorry for the late response.

1 answer

✓ Accepted answer

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

3 comments

0

I got the error: --> Workspace.Test.Experience:7: attempt to index local 'Leaderstats' (a nil value)

0

I got it to work thank you so much!

0

Your welcome

This discussion is preserved as it was. New answers, comments, and votes are closed.