I do not know what’s wrong. I use 2 variables and only 1 works, which is very unintuitive. I just want to save 2 of these variables but I get an error creating 2. Anyone can help me?
Variable fastlap NOT WORKING
okr WORKING
Error
Script
local datastore = game:GetService('DataStoreService')
local lapds = datastore:GetDataStore('Race')
local bind = game.ReplicatedStorage.lap
game.Players.PlayerAdded:Connect(function(Player)
local success, lap = pcall(function()
return lapds:GetAsync(Player.UserId)
end)
local leaderstats = Instance.new('Folder')
leaderstats.Name = "leaderstats"
leaderstats.Parent = Player
local okr = Instance.new("IntValue")
okr.Name = "Lap"
okr.Parent = leaderstats
local fastlap = Instance.new("StringValue")
fastlap.Name = "FastestLap"
fastlap.Parent = leaderstats
bind.Event:Connect(function(a,b)
if a == true and b == true then
okr.Value = game.ReplicatedStorage.ko.Value
fastlap.Value = game.ReplicatedStorage.Fast.Value
end
end)
if not lap then
lap = {
okr = 0;
fastlap = "No race";
}
end
okr.Value = lap.okr
fastlap.Value = lap.fastlap
wait(5)
end)
game.Players.PlayerRemoving:Connect(function(Player)
local leaderstats = Player:FindFirstChild('leaderstats')
if leaderstats then
local lap = {
okr = leaderstats.Lap.Value
fastlap = leaderstats.FastestLap.Value
}
if lap then
local success = pcall(function()
lapds:SetAsync(Player.UserId,lap)
end)
end
print(lap)
end
end)