HELP, Killstreak code [ Open Source ] dosent work!

Hey, I am working on a killstreak thing for when players kill eachother, and after 10 kills they get either, x3 speed, or x2 jump height. Please help!
I can’t figure out why it don’t work! please help!


if not SERVER then
	error( "This is here to tell you that you are dumb." )
end

local function OnPlayerDeath( ply, inflictor, attacker )
	
	if ply ~= attacker then 
		ply.streak = 0 
		attacker.streak = attacker.streak or 0 
		attacker.streak = attacker.streak + 1
		
		if killer.streak == 10 and math.random( 1, 2 ) == 2 then
		killer:SetRunSpeed( "300" ) 
		PrintMessage( HUD_PRINTTALK, "[Tier 10 package] you just got x3 run speed! with a 50% chance!
		
		elseif killer.streak == 10 and math.random( 1, 2 ) == 1 then
		killer:SetJumpPower( "200" ) PrintMessage( HUD_PRINTTALK, "[Tier 10 package] you just got x2 jump height! with a 50% chance!
		
		else
		
		end
	end
end

hook.Add( "PlayerDeath", "OnPlayerDeath", OnPlayerDeath )

Who’s killer?

Well, for starters you’re missing closing quotes and parens ( THESE: ") ) for your PrintMessages, that’s why the highlighting is all fucky. You would have noticed this if you’d checked the console for errors.

You’re passing strings instead of numbers to SetRunSpeed and SetJumpPower, and while I can’t be bothered to check the docs, I sincerely doubt they take strings.

You’re doing two successive calls to math.random, the result will differ each time, and the way you’ve set it up, there’s a 50% chance of increased run speed, 25% chance of increased jump power, and 25% chance that fuck all will happen.

You’ve got an empty else clause at the end of your if/elseif chain, you can delete the else keyword.

Your PrintMessage’s will broadcast to the whole server. Not sure if this is intended but it doesn’t seem likely.

Please call your hook something other than “OnPlayerDeath”.

I know this looks like a lot of bitching, but I’d rather tell you what’s wrong than feed you a working script. If I’m bored enough / feeling generous enough / I remember, I might post a better killstreaks script here sometime between now and the heat death of the universe.


if not SERVER then
	error( "This is here to tell you that you are dumb." )
end

local function ksm( ply, inflictor, attacker )
	
	if ply ~= attacker then 
		ply.streak = 0 
		attacker.streak = attacker.streak or 0 
		attacker.streak = attacker.streak + 1
		
		if attacker.streak == 10 and math.random( 1, 2 ) == 2 then
		attacker:SetRunSpeed( "300" ) 
		attacker:PrintMessage( HUD_PRINTTALK, "[Tier 10 package] you just got x3 run speed! with a 50% chance!" )
		
		elseif atacker.streak == 10 and math.random( 1, 2 ) == 1 then
		attacker:SetJumpPower( "200" ) 
		attacker:PrintMessage( HUD_PRINTTALK, "[Tier 10 package] you just got x2 jump height! with a 50% chance!" )
		
		end
	end
end

hook.Add( "PlayerDeath", "ksm", OnPlayerDeath )

Would that work?

I hope

You only fixed the first thing he said. I commented all of the errors so hopefully this will be helpful to your learning:


if SERVER then -- You don't have to error, just do this in-case. You can also do "if CLIENT then return end", but this is cleaner in my opinion
	hook.Add( "PlayerDeath", "ksm", function( ply, inflictor, attacker ) -- You don't have to declare a local function if you're just going to use it once
		if attacker:IsPlayer() and ply ~= attacker then -- Make sure we were killed by a player and the attacker is valid. NULL:IsPlayer() returns false.
			ply.streak = 0 
			attacker.streak = (attacker.streak or 0) + 1 -- We can combine both statements with parenthesis
			
			if attacker.streak == 10 then -- Just check attacker streak once instead of twice!
				if math.random( 1, 2 ) == 1 then 
					attacker:SetRunSpeed( attacker:GetRunSpeed() * 3 ) -- Send in a number to this function. Also, make sure we scale based on the previous run speed instead of hard values
					attacker:PrintMessage( HUD_PRINTTALK, "[Tier 10 package] you just got x3 run speed! with a 50% chance!" )
				else -- It was 2
					attacker:SetJumpPower( attacker:GetJumpPower() * 2 ) 
					attacker:PrintMessage( HUD_PRINTTALK, "[Tier 10 package] you just got x2 jump height! with a 50% chance!" )
				end
			end
		end
	end )
end