Im trying to make a kill streak script, but Im having a problem were it gives me this error
17:22:55.812 ServerScriptService.Script:17: attempt to index nil with 'Value' - Server - Script:17
17:22:55.812 Stack Begin - Studio
17:22:55.813 Script 'ServerScriptService.Script', Line 17 - Studio - Script:17
17:22:55.813 Stack End - Studio
is their anyway I can fix this?
local RunService = game:GetService("RunService")
local playerKills = {}
game:GetService("Players").PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local humanoid = character:WaitForChild("Humanoid")
local creator = humanoid:FindFirstChild("creator")
humanoid.Died:Connect(function()
if creator and creator.Value then
playerKills[creator.Value] += 3
end
end)
while task.wait() do
if playerKills[creator.Value] == 3 then
print("yay")
end
end
end)
end)
You should move the playerkills[creator.Value] check into the if creator check, and also define the creator in the humanoid.Died connection.
local RunService = game:GetService("RunService")
local playerKills = {}
game:GetService("Players").PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local humanoid = character:WaitForChild("Humanoid")
humanoid.Died:Connect(function()
local creator = humanoid:FindFirstChild("creator")
if creator and creator.Value then
playerKills[creator.Value] += 3
if playerKills[creator.Value] == 3 then
print("yay")
end
end
end)
end)
end)
Yeah, I think that this is how older leaderboard and tools worked. Theyâd have a ObjectValue named âcreatorâ that they would put into projectiles. The Value was the firing player, and when the projectile hurt a victim player, the projectile would put that creator tag into the humanoid so that the humanoid knew who hurt it.