Why do i get cash by killing myself?

Hello so i have the problem that when i kill myself i get cash what i don’t want!

code:

	plr.CharacterAdded:connect(function(char)
		local humanoid
		repeat
			humanoid = char:FindFirstChild("Humanoid")
			wait()
		until humanoid
		humanoid.Died:connect(function() 
			deaths.Value = deaths.Value + 1 
			local tag = humanoid:FindFirstChild("creator") 
			if tag then  
				local killer = tag.Value  
				if killer then   
					local killername = killer.Name
					killer.leaderstats.Kills.Value = killer.leaderstats.Kills.Value + 1
					killer.leaderstats.Cash.Value = killer.leaderstats.Cash.Value + 50
					killEvent:FireAllClients(plr,killername)
				end   
			end 
		end)     
	end)

Why not just add a check over here?

if killer and killer ~= plr then   
	local killername = killer.Name
	killer.leaderstats.Kills.Value = killer.leaderstats.Kills.Value + 1
	killer.leaderstats.Cash.Value = killer.leaderstats.Cash.Value + 50
	killEvent:FireAllClients(plr,killername)
end   

It would be preferable if the tag script itself wouldn’t be able to tag the own player as right now the player could steal his own kill, all this does is prevent the player from getting rewards if he is tagged by himself.

1 Like

if you dont want cash then:

	plr.CharacterAdded:connect(function(char)
		local humanoid
		repeat
			humanoid = char:FindFirstChild("Humanoid")
			wait()
		until humanoid
		humanoid.Died:connect(function() 
			deaths.Value = deaths.Value + 1 
			local tag = humanoid:FindFirstChild("creator") 
			if tag then  
				local killer = tag.Value  
				if killer then   
					local killername = killer.Name
					killer.leaderstats.Kills.Value = killer.leaderstats.Kills.Value + 1
					--killer.leaderstats.Cash.Value = killer.leaderstats.Cash.Value + 50
					killEvent:FireAllClients(plr,killername)
				end   
			end 
		end)     
	end)

no,that wasn’t my point I want to get cash if i kill someone but only if it isn’t me!

Does this not work for you?

Just do what @mniao said

plr.CharacterAdded:connect(function(char)
	local humanoid
	repeat
		humanoid = char:FindFirstChild("Humanoid")
		wait()
	until humanoid
	humanoid.Died:connect(function() 
		deaths.Value = deaths.Value + 1 
		local tag = humanoid:FindFirstChild("creator") 
		if tag then  
			local killer = tag.Value  
			if killer and humanoid.Parent.Name ~= plr.Name then   
				local killername = killer.Name
				killer.leaderstats.Kills.Value = killer.leaderstats.Kills.Value + 1
				--killer.leaderstats.Cash.Value = killer.leaderstats.Cash.Value + 50
				killEvent:FireAllClients(plr,killername)
			end   
		end 
	end)     
end)
1 Like

yep thank you very much this finally works for me nice guy XD :smiley:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.