I have made a script that I think should show the players speed in the leaderstats. But the script does not even work. The error is: "ServerScriptService.Script:3: attempt to call a nil value" Here's they script:
game.Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.New("Folder",player) leaderstats.Name = "leaderstats" local Speed = Instance.New("IntValue", leaderstats) Speed.Name = leaderstats while true do wait() Speed = player.Character.Humanoid.WalkSpeed end end)
I hope you can help! I should see it soon if you post an answer in the next 2 hours so please leave one!
There are so many errors in this script. In line 3 and 6, always use Instance.new()
not Instance.New()
. In line 7 you're naming an IntValue an instance instead of a string (string is a group of words inside two quotation marks; they usually appear green when coding), which will cause errors. And lastly, in line 11, you're trying to change an instance into a number, which will cause AN ERROR. Instead, use Speed.Value
.
This is the fixed script:
game.Players.PlayerAdded:Connect(function(player) local character = player.Character or player.CharacterAdded:Wait() local leaderstats = Instance.new("Folder", player) leaderstats.Name = "leaderstats" local Speed = Instance.new("IntValue", leaderstats) Speed.Name = "Speed" while true do task.wait() Speed.Value = character:FindFirstChildOfClass("Humanoid").WalkSpeed end end)
Hopefully this script works!
If you feel discouraged while reading my answer, don't be. I'm not mad, I'm helping you with your script. I understand you're new to scripting and that's fine. I hope you will get better and have a nice day!
This is my leaderstats script you should be able to work your variables into this
game.Players.PlayerAdded:Connect(function (plr) local stats = Instance.new("BoolValue",plr) stats.Name = "leaderstats" local cash = Instance.new("IntValue",stats) cash.Name = "Credits" cash.Value = 500 end)
I think your issue is Line 7 when your giving Speed the name of leaderstats. also Speed is the name of the currency or stat so you wouldent want speed to = player.Character.Humanoid.WalkSpeed
it should be Speed.Value = player.Character.Humanoid.WalkSpeed
Im newer to scripting but I hope this helps you out!