i was trying to make a sell button and when i tried it it says:
"Workspace.Sell.Script:7: attempt to index nil with 'Value'"
here's the script for the sell:
script.Parent.Touched:Connect(function(hit) local player = game.Players:GetPlayerFromCharacter(hit.Parent) if player then local leaderstats = player:findFirstChild("leaderstats") local Cash = player:findFirstChild("Cash") local Strength = player:findFirstChild("Strength") if Strength.Value > 0 then Cash.Value = Cash.Value + Strength.Value*1 Strength.Value = 0 end end end)
You are looking for the cash inside of the player itself as opposed to the leaderstats. You meant to look in the latter therefore Instance::FindFirstChild
returns nil.
local Players = game:GetService("Players") script.Parent.Touched:Connect(function(part) local player = Players:GetPlayerFromCharacter(part.Parent) if player then local leaderstats = player.leaderstats local Cash = leaderstats.Cash local Strength = leaderstats.Strength if Strength.Value > 0 then Cash.Value = Cash.Value + Strength.Value Strength.Value = 0 end end end)
And by the way you don't need Instance:FindFirstChild
if you are actually able to guarantee that an instance with the provided name exists. Btw multiplying by 1 is redundant since any number multiplied by 1 results in itself