hello, I made a script that's supposed to change the players hat depending on how many kills they have, but it doesn't work and in the output it says Workspace.ht518.Script:1: attempt to index nil with 'leaderstats'
if game.Players.LocalPlayer.leaderstats.Kills.Value == 10 then script.Parent.hat:Destroy() game.ServerStorage.hat1:Clone() game.ServerStorage.hat1.Parent = script.Parent end
can anybody help me with this, it is a (Server) Script in StarterCharacterScripts
Try this
Make a Server script in ServerScriptService and use this code
game:GetService("Players").PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player local kills = Instance.new("IntValue") kills.Name = "Kills" kills.Value = 0 kills.Parent = leaderstats player.CharacterAdded:Connect(function(char) char:WaitForChild("Humanoid").Died:Connect(function() local creator = char:WaitForChild("Humanoid"):FindFirstChild("creator") if creator and creator.ClassName == "ObjectValue" then local murderer = creator.Value murderer:WaitForChild("leaderstats"):WaitForChild("Kills").Value += 1 end end) if kills.Value >= 10 then char:FindFirstChild("hat"):Destroy() local cloneHat = game:GetService("ServerStorage"):FindFirstChild("hat1"):Clone() cloneHat = script.Parent end end) end)