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)
Hello, I hope this will help:
local cost = 100 local dataStore = game:GetService("DataStoreService") local data = dataStore:GetDataStore("SavedData") 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 = player.leaderstats.Bucks.Value - cost -- I know this works in python, but I changed that to be sure it will work player:WaitForChild("Areas"):WaitForChild("HasForest").Value = true script.Parent.Transparency = 1 script.Parent.CanCollide = false local dataToSave = { ownsForest = "true" } data:SetAsync(player.UserId, dataToSave) wait(0.5) script.Disabled = true end end end) game:GetService("Players").PlayerAdded:Connect(function(player) -- Dudeee, if you didnt set data store to save the value it wont work, because when you join game it is false by default local hasSavedData = data:GetAsync(player.UserId) if hasSavedData then if hasSavedData.ownsForest == "true" then script.Parent.Transparency = 1 script.Parent.CanCollide = false end end end)