Script with proximity prompt not work while code should be right

nothing changed. still wont work.

script.Parent.Triggered:Connect(function(plr)
	local wood = game:GetService("Players"):FindFirstChild(plr).leaderstats.Wood
	wood.Value = wood.Value + 1
	print('succes + 1')
	script.Parent.Parent:Destroy()
	print('succes destroyed')
end)

print the player
as in
print(plr)

script.Parent.Triggered:Connect(function(plr)
	local wood = game:GetService("Players"):FindFirstChild(plr).leaderstats.Wood
	print("plr")
	wood.Value = wood.Value + 1
	print('succes + 1')
	script.Parent.Parent:Destroy()
	print('succes destroyed')
end)
like this?

it has to be as in print(plr) exactly like that

nothing printed when i clicked play

show another video also show the output stuff

robloxapp-20230415-1534558.wmv (2.0 MB)

Workspace.Tree4.TreeStem2.ProximityPrompt.Script:2: attempt to index nil with ‘leaderstats’

Script ‘Workspace.Tree4.TreeStem2.ProximityPrompt.Script’, Line 2

make the first line inside of the function print(plr) and see what it prints

Workspace.Tree4.TreeStem2.ProximityPrompt.Script:3: attempt to index nil with ‘leaderstats’
it prints plr 2 times. so it gets stuck at the + value line.

script.Parent.Triggered:Connect(function(plr)
	print("plr")
	local wood = game:GetService("Players"):FindFirstChild(plr).leaderstats.Wood
	print("plr")
	wood.Value = wood.Value + 1
	print('succes + 1')
	script.Parent.Parent:Destroy()
	print('succes destroyed')
end)

you did it wrong dont put “” it should print your name

i ment to not put “”
iiiiiiiiiiiiiiii

yeah it printed my name but i get:

Workspace.Tree4.TreeStem2.ProximityPrompt.Script:3: attempt to index nil with ‘leaderstats’

try removing this game:GetService(“Players”):FindFirstChild(plr) and replace it with plr if it doesnt work then put game:GetService(“Players”):FindFirstChild(plr) back

script.Parent.Triggered:Connect(function(plr)
	print(plr)
	local wood = game.plr.leaderstats.Wood
	print("plr")
	wood.Value = wood.Value + 1
	print('succes + 1')
	script.Parent.Parent:Destroy()
	print('succes destroyed')
end)

this?

remove game.


1 Like

it works thank you so much for the help!