Error in sell script

I tried to create a sell place but it is returning an error like this
image
This is the script

local part = script.Parent
part.Touched:Connect(function(HIT)
	local H = HIT.Parent:FindFirstChild("Humanoid")
	if H then
		local player = game.Players:GetPlayerFromCharacter(HIT.Parent)
		if player then
			local leaderstats = player:WaitForChild("leaderstats")
			local Currency = leaderstats.Coins
			local Selling = leaderstats.Strength
			if Selling.Value > 0 then
				Currency.Value = Currency.Value + Selling.Value *1
				Selling.Value = 0
				script.Parent.Sound:Play()
			end
		end
	end

end)


This is the script where I made the variable coins

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Model")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local money = Instance.new("IntValue")
	money.Name = "Coins"
	money.Value = 0
	money.Parent = leaderstats
	
	local Strength = Instance.new("IntValue")
	Strength.Name = "Strength"
	Strength.Value = 0
	Strength.Parent = leaderstats
end)

This is the line where it gives error
image

Please help me
superkingburger1456

try this

local Currency = leaderstats:WaitForChild("Coins")

Ok sure let me try that real quick

As a debugging measure, you can check if Coins is even in the leaderstats folder by playtesting and at the top, clicking the client button to go into server. Then look in the explorer>Players>(your username)>leaderstats>Coins to make sure it’s there.

I tried it but when I click the tool (which should give me strength) it did not and this error came

image

script.AddPoints.OnServerEvent:Connect(function(plr)
	plr.leaderstats.Strength.Value = plr.leaderstats.Value+10
end)

leaderstats is a folder! You are using a wrong object

Ok let me try that to see if it works

fine but which object should I use then

script.AddPoints.OnServerEvent:Connect(function(plr)
	plr.leaderstats.Strength.Value += 10
end)

you mean

script.AddPoints.OnServerEvent:Connect(function(plr)
	plr.leaderstats.Strength.Value = plr.leaderstats.Strength.Value+10
end)

It should be:


plr.leaderstats.Strength.Value = plr.leaderstats.Strength.Value+10

Or

plr.leaderstats.Strength.Value += 10

I do believe you meant:

plr.leaderstats.Strength.Value = plr.leaderstats.Strength.Value+10

Yep its there see down
image

Try making the leaderstats a “Folder” not a “Model”?

Like this:

local leaderstats = Instance.new("Folder")
2 Likes

try repeating until it got a value

repeat
local leaderstats = player:WaitForChild("leaderstats").ValueName
if leaderstats then
break
end
wait()
until false

Thanks man appreciate it

Thanks for the help

1 Like

Thanks to @aquawrsp @bookgamery555gta @chubbypig332211 @SloppyBanana225 for the help

1 Like

Also one more thing:

local leaderstats = Instance.new("Folder", player)
	leaderstats.Name = "leaderstats"
	
	local money = Instance.new("IntValue", leaderstats)
	money.Name = "Coins"
	money.Value = 0
	
	local Strength = Instance.new("IntValue", leaderstats)
	Strength.Name = "Strength"
	Strength.Value = 0

This will make the function a little shorter while doing the same thing.

Ok let me see if this work too

If it doesn’t, then it’s fine. It will work if you keep it the way it was. This is just a way to shorten it down, that’s all.