I'm trying to make a killstreak system that if your killstreak is 5 or more you get a crown and if it's less than 5 you lose the crown. But the problem is that the RemoveCrown function is giving me an error saying like I said in the title:
19: attempt to index a nil value.
Script:
-- Functions
function AddCrown(Player)
repeat wait() until Player.Character
local Char = Player.Character
local Head = Char.Head
local Crown = game.ServerStorage.CrownPart:Clone()
Crown.Parent = Head
while true do
wait(0.01)
Crown.CFrame = CFrame.new(Head.Position + Vector3.new(0, 3, 0))
end
end
function RemoveCrown(Player)
Player.Character.Head:FindFirstChild("CrownPart"):Destroy()
end
-- Runs functions
game.Players.PlayerAdded:connect(function(Player)
repeat wait() until Player.Character
local Killstreak = Player:WaitForChild("PlayerValues").Killstreak
local Char = Player.Character
while true do
wait(0.1)
if Killstreak.Value >= 5 then
AddCrown(Player)
else
RemoveCrown(Player)
end
end
end)
I would really appreciate it if you help me with my problem, Plus I'll accept your answer.
Thanks, MajinBluee

1 comment
It might be that the crown doesn't exist