#Problem with "attempt to index nil" for a leaderstats
1 messages · Page 1 of 1 (latest)
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)
Doesnt working the "player.CharacterAdded:Wait" is underline in red
why
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
I have the same error
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 ?
I have to add a "wait ?
do i need to change the leaderstats?
** You are now Level 1! **
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
yes thank you:) !!!
