When I use this in studio, it works. When I play the game normally, the leaderboard is not there and it does nothing when I die. Please tell me what I did wrong, thank you.
Player = game.Players.LocalPlayer game.Players.PlayerAdded:connect(function(Player) local stats = Instance.new("IntValue") stats.Parent = Player stats.Name = "leaderstats" local Points = Instance.new("IntValue") Points.Parent = stats Points.Name = "Pointz" deaths = Instance.new("IntValue") deaths.Parent = stats deaths.Name = "Deaths" game.Players.LocalPlayer.CharacterAdded:connect(function() game.Players.LocalPlayer.Character.Humanoid.Died:connect(function() deaths.Value = deaths.Value + 1 local deathGui = Instance.new("ScreenGui") deathGui.Parent = game:GetService("Players").LocalPlayer.PlayerGui local deathText = Instance.new("TextBox") deathText.Parent = deathGui deathText.Text = "YOU SUCK, "..game.Players.LocalPlayer.Name deathText.FontSize = "Size96" deathText.Position = UDim2.new(0.5,0,0.5,0) deathText.BackgroundTransparency = 1 deathText.TextColor3 = Color3.new(255,255,255) wait(5) deathGui:Remove() end) end) end)
Alright, so you've made it clear you're not using a localscript, so here's your problem.
The term (when accessing the "Players" service) "LocalPlayer
" refers to the client's player. This can only be used when using a localscript, server scripts do not have a "LocalPlayer
". Here's how the script should go.
game.Players.PlayerAdded:connect(function(Player) --This listens for when a player is added and defines the `argument ` "Player" as the aforementioned player who joined. local stats = Instance.new("IntValue") stats.Parent = Player stats.Name = "leaderstats" local Points = Instance.new("IntValue") Points.Parent = stats Points.Name = "Pointz" deaths = Instance.new("IntValue") deaths.Parent = stats deaths.Name = "Deaths" Player.CharacterAdded:connect(function() Player.Character.Humanoid.Died:connect(function() deaths.Value = deaths.Value + 1 local deathGui = Instance.new("ScreenGui") deathGui.Parent = Player.PlayerGui local deathText = Instance.new("TextBox") deathText.Parent = deathGui deathText.Text = "YOU SUCK, "..Player.Name:upper() deathText.FontSize = "Size96" deathText.Position = UDim2.new(0.5,0,0.5,0) deathText.BackgroundTransparency = 1 deathText.TextColor3 = Color3.new(255,255,255) wait(5) deathGui:Destroy() --don't use deprecated methods ; ) end) end) end)
I'm not the best at explaining, but this should fix your issue :)