#Problem with "attempt to index nil" for a leaderstats

1 messages · Page 1 of 1 (latest)

sour crane
#

do

#
local player = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
local character = player.Character or player.CharacterAdded:Wait()

local NumberValue = character:WaitForChild("Pressed")

script.Parent.ClickDetector.MouseClick:Connect(function(click)
  if NumberValue and NumberValue:IsA("NumberValue") then
    NumberValue.Value += 1
  end
end)
oblique moss
#

Doesnt working the "player.CharacterAdded:Wait" is underline in red

sour crane
#

yep

#

i can explain why ur script is not worked

oblique moss
#

why

sour crane
#

It didn't work cuz ur character didn't have time to load and cuz of this it gave out nil

#

so i added this to wait for character to load and continue a script

#

and now it should work

oblique moss
#

I have the same error

sour crane
#

hm

#
local player = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
local character = player.Character or player.CharacterAdded:Wait()

local NumberValue = character:WaitForChild("Pressed")

script.Parent.ClickDetector.MouseClick:Connect(function(click)
  if NumberValue and NumberValue:IsA("NumberValue") then
    NumberValue.Value += 1
  end
end)
#

maybe this one ?

oblique moss
#

i have this error

#

Infinite yield possible on 'ImWearyFace:WaitForChild("Pressed")'

sour crane
#

a

#

yep

oblique moss
#

I have to add a "wait ?

sour crane
#

ur character is dont have child called Pressed

#

u forgot about leaderstats ;-;

oblique moss
unborn socketBOT
#

studio** You are now Level 1! **studio

sour crane
#

no

#

wait

#
local player = game.Players.PlayerAdded:Wait()
local character = player.Character or player.CharacterAdded:Wait()

local NumberValue = player.leaderstats.Pressed

script.Parent.MouseClick:Connect(function(click)
    if NumberValue and NumberValue:IsA("IntValue") then
        NumberValue.Value += 1
    end
end)
#

this one should work

oblique moss
sour crane
#

np

#

ur made 2 errors in a script btw

#

here (its fixed variant)

oblique moss
#

ok