Hello,

I am asking a script to retrieve an IntValue from a folder in my localplayer. It can retrieve 2 others, but not one. All scripts are exactly the same.

https://imgur.com/a/LwXFb5i

Code for setting the IntValue:

local vitocost = 18431
local transit = 11418
local corsacost = 3600

game.ReplicatedStorage.CarEvents.Vito.OnServerEvent:Connect(function(plr)
	local Cash = plr.leaderstats.GBP
	if vitocost and Cash.Value >= vitocost then
		Cash.Value = Cash.Value - vitocost
		plr.OwnedCars.Vito.Value = 1
	end
end)

game.ReplicatedStorage.CarEvents.Transit.OnServerEvent:Connect(function(plr)
	local Cash = plr.leaderstats.GBP
	if transit and Cash.Value >= transit then
		Cash.Value = Cash.Value - transit
		plr.OwnedCars.Transit.Value = 1
	end
end)

game.ReplicatedStorage.CarEvents.Corsa.OnServerEvent:Connect(function(plr)
	local Cash = plr.leaderstats.GBP
	if corsacost and Cash.Value >= corsacost then
		Cash.Value = Cash.Value - corsacost
		plr.OwnedCars.Corsa.Value = 1
	end
end)

Code for the datastore saving the value:

local players = game:GetService("Players")
local dataStore = game:GetService("DataStoreService")
local cardatastore1 = dataStore:GetDataStore("Car1a")
local cardatastore2 = dataStore:GetDataStore("Car2")
local cardatastore3 = dataStore:GetDataStore("Car3a")


players.PlayerAdded:Connect(function(player)
	local folder = Instance.new("Folder")
	folder.Name = "OwnedCars"
	folder.Parent = player
	
	local car1 = Instance.new("IntValue")
	car1.Name = "Vito"
	car1.Parent = player.OwnedCars
	car1.Value = cardatastore1:GetAsync(player.UserId) or 0
	cardatastore1:SetAsync(player.UserId, car1.Value)
	
	local car2 = Instance.new("IntValue")
	car2.Name = "Transit"
	car2.Parent = player.OwnedCars
	car2.Value = cardatastore2:GetAsync(player.UserId) or 0
	cardatastore2:SetAsync(player.UserId, car2.Value)
	
	local car3 = Instance.new("IntValue")
	car3.Name = "Corsa"
	car3.Parent = player.OwnedCars
	car3.Value = cardatastore3:GetAsync(player.UserId) or 0
	cardatastore3:SetAsync(player.UserId, car3.Value)

	
		car1.Changed:Connect(function()
		cardatastore1:SetAsync(player.UserId, car1.Value)
	end)

		car2.Changed:Connect(function()
		cardatastore2:SetAsync(player.UserId, car2.Value)
	end)
	
		car3.Changed:Connect(function()
		cardatastore3:SetAsync(player.UserId, car3.Value)
	end)

	end)

The 'Vito' and 'Transit' are working perfectly fine as intended.

1 comment

0

Just a note - the IntValue is retrieved sometimes when you join, but others it is not. It is retrieved every time for 'Vito' and 'Transit'