**I am programing a game where you collect trash, exchange for money and then use your money, Im trying to make a pressure plate , when you step on it, you buy the item if you have enough money(like the survive the disasters one) , BUT it isn't working! **
`function ontouched (part)
local RS = game:GetService("ReplicatedStorage")
local item = RS:WaitForChild("Sword")
local price = 100 -- Change Your Price Here
local Player = game.Players.LocalPlayer
local stats = Player:WaitForChild("leaderstats")
if stats.Pennys.Value == price then -- Change the Money to your Currency Name
stats.Pennys.Value = stats.Pennys.Value - price
local cloned = item:Clone()
local cloned2 = item:Clone()
cloned2.Parent = Player.Backpack
cloned.Parent = Player.StarterGear
end
end
-- the player gets an error "attempt to index local 'Player' (a nil value)" please help
script.Parent.Touched:Connect(ontouched)
`

1 comment
You can also just do: item:Clone().Parent = Player.Backpack and item:Clone().Parent = Player.StarterGear. And, if you're not using a localscript, LocalPlayer does not exist.