db = true cooldown = script.Parent.Cooldown Kaioken = script.Parent local player = game.Players.LocalPlayer.Character:FindFirstChild("Humanoid") Kaioken.MouseButton1Down:Connect(function() if db == true then player.MaxHealth.Value = player.MaxHealth.Value +5 player.Walkspeed.Value = player.Walkspeed.Value +5 wait (5) player.MaxHealth.Value = player.MaxHealth.Value -5 player.Walkspeed.Value = player.Walkspeed.Value -5 db = false cooldown.Text = "Cooldown: 5" wait (1) cooldown.Text = "Cooldown: 4" wait (1) cooldown.Text = "Cooldown: 3" wait (1) cooldown.Text = "Cooldown: 2" wait (1) cooldown.Text = "Cooldown: 1" wait(1) cooldown.Text = "Cooldown: 0" db = true end end)
Thats my script I use and it says attempt to index upvalue 'player' (a nil value) Help meh plz
What incapaz said is correct. The gui usually loads before the player, so at the time the script ran, there was no LocalPlayer.Character
A hacky fix is to add wait()
s to the beginning of your script, but that doesn't solve the problem.
The proper way is to use some form of wait on the character.
Here's one solution:
local db = true local cooldown = script.Parent.Cooldown local Kaioken = script.Parent local player = game.Players.LocalPlayer if not player.Character then player.CharacterAdded:wait() end local character = player.Character if not character:FindFirstChild("Humanoid”) then character:WaitForChild(”Humanoid”) end local human = character.Humanoid
Remember that this is just one solution, and I'm sure there are better ways to do this. But that's for you to discover.
Even though you didn't ask, I'll fix the rest of your script, too.
Kaioken.MouseButton1Down:Connect(function() if db then db = false human.MaxHealth = human.MaxHealth +5 human.Walkspeed = human.Walkspeed +5 wait (5) human.MaxHealth = human.MaxHealth -5 human.Walkspeed = human.Walkspeed -5 for i = 5, 0, -1 do cooldown.Text = "Cooldown: "..i wait (1) end db = true end end)