#Potion system

1 messages · Page 1 of 1 (latest)

shell crest
#

I maked a potion system but it do nothing

#

here are the script

#

local dataStoreService = game:GetService("DataStoreService")
local DS = dataStoreService:GetDataStore("DataStoreName")

local function saveData(plr)

local usedCode = {}

for _, code in pairs(plr.Codes:GetChildren()) do
    table.insert(usedCode, code.Name)
end

local tableToSave = {
    plr.leaderstats.Points.Value,
    plr.Potions["PointsBoostActive?"].Value,
    plr.Potions["PointsBoostTime"].Value,
    usedCode,
}

local success, errorMessage = pcall(DS.SetAsync, DS, plr.UserId, tableToSave)
if success then
    print("Data has been saved")
else
    print(errorMessage)
end

end

game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Wait()

local leaderstats = Instance.new("Folder", plr)
leaderstats.Name = "leaderstats"

local points = Instance.new("IntValue", leaderstats)
points.Name = "Points"
points.Value = 0
#

local potionFolder = plr:FindFirstChild("Potions")
if not potionFolder then
potionFolder = Instance.new("Folder", plr)
potionFolder.Name = "Potions"
end

local pointsBoostTime = potionFolder:FindFirstChild("PointsBoostTime") or Instance.new("IntValue", potionFolder)
pointsBoostTime.Name = "PointsBoostTime"
pointsBoostTime.Value = 0

local pointsBoostActive = potionFolder:FindFirstChild("PointsBoostActive?") or Instance.new("BoolValue", potionFolder)
pointsBoostActive.Name = "PointsBoostActive?"
pointsBoostActive.Value = false

local temp = plr.Codes:FindFirstChild("testCode1")


local data = nil
local success, errorMessage = pcall(function()
    data = DS:GetAsync(plr.UserId)
end)
#

if success and data then
points.Value = data[1]
pointsBoostActive.Value = data[2]
pointsBoostTime.Value = data[3]
local usedCodes = data[4] or {}

    local codeFolder = plr:FindFirstChild("Codes") 
    for _, codeName in pairs(usedCodes) do
        local codeValue = Instance.new("BoolValue", codeFolder)
        codeValue.Name = codeName
    end
else
    warn(errorMessage)
end

if pointsBoostActive == true then
    local potionGui = plr:WaitForChild("PlayerGui"):WaitForChild("Potion"):WaitForChild("PotionTime")
    
end
#

while task.wait(1) do
if potionFolder["PointsBoostActive?"].Value == true then
potionFolder["PointsBoostTime"].Value -= 1
end
points.Value += 1
if pointsBoostActive.Value == true then
points.Value += 2
end
if plr.Potions["PointsBoostActive?"].Value == true then
if plr.Potions["PointsBoostTime"].Value <= 0 then
plr.Potions["PointsBoostActive?"].Value = false
plr.Potions["PointsBoostTime"].Value = 0
end
end
end
end)

#

game.Players.PlayerRemoving:Connect(function(plr)
saveData(plr)
end)

game:BindToClose(function()
for _, player in ipairs(game.Players:GetChildren()) do
task.spawn(saveData, player)
end
end)