Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to stop datastore returning a string?

Asked by
Meqolo 78
6 years ago

For some reason my datastore is returning " " and I keep getting errors about an attempt to compare a string with a number.

Code:

local DSS = game:GetService("DataStoreService")
ArrestDS = DSS:GetDataStore("Arrest")
game.Players.PlayerAdded:Connect(function(plr)
    local plra = Instance.new("StringValue")
    plra.Name = plr.Name
    plra.Parent = script.Folder
    local Time = ArrestDS:GetAsync(plr.Name .. ":" .. plr.UserId)
    print(Time)
    if Time == " " or Time == nil or Time == "" then
        ArrestDS:SetAsync(plr.Name .. ":" .. plr.UserId, tonumber(0))
    elseif Time > 0 then
        local jailgui = script.JailUI:Clone()
        jailgui.Parent = plr.PlayerGui
        plr.TeamColor = BrickColor.new("Magenta")
    end
end)

game.ReplicatedStorage.Cuffs.OnServerEvent:Connect(function(plr, otherplr, state, arresttime)
    if state == "Cuff" then
        script.Folder:FindFirstChild(plr.Name).Value = otherplr
        cuff(plr, otherplr)
    elseif state == "Uncuff" then
        script.Folder:FindFirstChild(plr.Name).Value = ""
        uncuff(plr, otherplr)
    end
    if state == "Arrest" then
        local jailgui = script.JailUI:Clone()
        jailgui.Parent = game.Players[otherplr].PlayerGui
        game.Players[otherplr].TeamColor = BrickColor.new("Magenta")
        ArrestDS:SetAsync(otherplr .. ":" .. game.Players[otherplr].UserId, arresttime)
        while wait(1) do
            local success = pcall(function()
                return ArrestDS:IncrementAsync(otherplr .. ":" .. game.Players[otherplr].UserId, -1)
            end)
            print(ArrestDS:GetAsync(otherplr .. ":" .. game.Players[otherplr].UserId))
        end
    end
end)

function cuff(plr,otherplr)
    game.Workspace[otherplr].Torso.Anchored = true
    game.Workspace[otherplr].Torso.CanCollide = false
    game.Workspace[otherplr].Head.CanCollide = false
    game.Workspace[otherplr].Torso.Anchored = false
    while script.Folder:FindFirstChild(plr.Name).Value == otherplr do
        wait(0.00000001)
        game.Workspace[otherplr].Torso.CFrame = game.Workspace[plr.Name].Torso.CFrame * CFrame.new(0,0,-2.5)
    end
end

function uncuff(plr,otherplr)
    game.Workspace[otherplr].Torso.CanCollide = true
    game.Workspace[otherplr].Head.CanCollide = true
end
0
You should not be saving data each time OnServerEvent is fired. Save data when it is needed User#5423 17 — 6y
0
How are you triggering the event? Can you include the local script code. User#5423 17 — 6y
0
This is happening because the variable "Time" is a string. On line 11, you are comparing a string (time) with a number (zero) UgOsMiLy 1074 — 6y

Answer this question