I'm making an area inside of my game, I made when you touch a part and you have enough bucks it opens and then a value goes true making sure that they own it, So the value saves, But I wrote a code to check if they have that value true, It opens, But it doesn't work, Can anyone help?
Here's my code:
local cost = 100
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if player.leaderstats.Bucks.Value >= cost then
player.leaderstats.Bucks.Value -= cost
player:WaitForChild("Areas"):WaitForChild("HasForest").Value = true
script.Parent.Transparency = 1
script.Parent.CanCollide = false
script.Disabled = true
end
end
end)
game:GetService("Players").PlayerAdded:Connect(function(player)
if player:WaitForChild("Areas"):WaitForChild("HasForest").Value == true then
script.Parent.Transparency = 1
script.Parent.CanCollide = false
end
end)

2 comments
Shouldn't Line09 read 'if player.leaderstats.Bucks.Value >= cost then player.leaderstats.Bucks.Value = player.leaderstats.Bucks.Value - (cost)
The taking away cash works