Hey, i wanted to make a script where when the player touches a block he gets money.
But it doesnt work. It says that statis is a nil value.
What am i doing wrong in this code?
script.Parent.Touched:Connect(function(hit)
local character = hit.parent
local stats = character:findFirstChild("leaderstats")
local player = game.Players:GetPlayerFromCharacter(character)
if player then
local money = stats:FindFirstChild("Cash")
local add = 50
money.Value = money.Value + add
print(money.Value)
end
end)

4 comments
stats is a string
that was a mistake, edited the code how it actually is
":findFirstChild" is deprecated. Use ":FindFirstChild" instead. Generally the leaderstats are kept in the player. I don't know what you are doing or where you are putting your leaderstats, but I think that might be your issue.
You are looking for the leaderstats in the character.