How to prevent a rocket launcher from giving a ton of levels from one person

So, I made a rocket launcher but it seems to give to many levels when I only want it to give one level per player killed.

for i,v in pairs(GetTouchingParts(exp)) do
			if game.Players:GetPlayerFromCharacter(v.Parent) and v.Parent:FindFirstChild("Humanoid") and game.Players:GetPlayerFromCharacter(v.Parent).Team ~= plr.Team then
				v.Parent.Humanoid:TakeDamage(stats.dmg)
				if not v.Parent:FindFirstChild("Humanoid") or v.Parent.Humanoid.Health <= 0 then
					plr.Level.Value = plr.Level.Value + 1
				end
			end
		end
1 Like

I would recommend using a tagging system for awarding levels to a player over using your current method, which might be inconsistent.

Basically, when ever the RPG damages a player, you’d insert a “tag” into their humanoid, like so:

local tag = Instance.new("ObjectValue", hit_humanoid)
tag.Name = "tag"
tag.Value = attacking_player
game.Debris:AddItem(tag, 5) --Get rid of the tag after a time.

And then, you could connect a OnDied event for each player’s character each time they spawn, and from there you can iterate through the tags and determine what players need to be awarded.

local awarded_players = {}
for I,v in pairs(dead_player.Humanoid:GetChildren()) do
if v.Name == "tag" and not awarded_players[v.Value] then
awarded_players[v.Value] = true
--Give the player a level or something, which would be referenced as the value of 'v'
end
end

Hope this helps! :slight_smile:

1 Like

thanks ill try it :slight_smile:

You could do something like this:

local alreadyTagged = nil

for i,v in pairs(GetTouchingParts(exp)) do
		if game.Players:GetPlayerFromCharacter(v.Parent) and v.Parent:FindFirstChild("Humanoid") and game.Players:GetPlayerFromCharacter(v.Parent).Team ~= plr.Team then
			v.Parent.Humanoid:TakeDamage(stats.dmg)

            if alreadyTagged ~= v.Parent.Name then 

			    if not v.Parent:FindFirstChild("Humanoid") or v.Parent.Humanoid.Health <= 0 then
				    plr.Level.Value = plr.Level.Value + 1
                    alreadyTagged = v.Parent.Name
			    end
            end
		end
	end

I have not tested this code, might have typos.
Good luck!

Edit: this method will not let you give levels to someone twice in a row, but if you shoot player A and then player B you could then shoot player A and you would get a level again

Yeah, that’s why I deleted the message. Too busy to explain to OP the tag solution so I decided to just delete the message.

A cleaner solution for tagging would be to use CollectionService. I feel that using an object for a “tag” is just clutter :slight_smile:

3 Likes