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

Creating a save script, Data store number Incrementing by 100??

Asked by 6 years ago
Edited 6 years ago

Hoi there (Please don't downvote, just tell me what is the problem and I will fix it) So, I have attempted to make a script that saves an items position, it has has a variable which tells it's data store value and before I load it into my game, I have to check the Data store number so the position of other items won't get mixed up with other positions and all...

Error: I am using a loop which is cause an Int value to increment A LOT BY LIKE 100!! Any help would be great

Script In case you need it in order to help me:

wait(1)
local Ds = game:GetService("DataStoreService"):GetDataStore("Testing")
local saving = {} or nil
local key = "Player -- "..game.Players.LocalPlayer.UserId
saving = Ds:GetAsync(key)
print(saving)

local mouse = game.Players.LocalPlayer:GetMouse()
local moveModel = workspace:WaitForChild("Wood Crate")
local itemname = workspace.Tycoons.BasePlate:WaitForChild("ItemName")
-- don't detect the model we're moving
mouse.TargetFilter = moveModel

function MoveItem()
    -- make sure the mouse is pointing at something
    if mouse.Target then
        -- where we cast our ray from (shifted slightly up so the ray will hit the surface we're hovering)
        local origin = mouse.Hit.p + Vector3.new(0, 0.1, 0)

        -- cast our ray and get our normal, which is a unit vector
        local ray = Ray.new(origin, Vector3.new(0, -1, 0))
        local hit, pos, normal = workspace:FindPartOnRay(ray, moveModel)

        -- get the perpendicular vector and the angle between the two
        local cross = Vector3.new(0, 1, 0):Cross(normal)
        local angle = math.asin(cross.magnitude) -- division by 1 is redundant

        moveModel:SetPrimaryPartCFrame(
            CFrame.new(mouse.Hit.p) -- position
            * CFrame.fromAxisAngle(cross.magnitude == 0 and Vector3.new(1) or cross.unit, angle) -- angle, cross must not be Vector3.new()
        )
    end
end

-- check every frame
while wait() do
    wait(.01)
    mouse.Button1Down:connect(function()
        game.Players.LocalPlayer.leaderstats["Item Data Store Name"].Value = game.Players.LocalPlayer.leaderstats["Item Data Store Name"].Value + 1
        if workspace.Tycoons.BasePlate.IsPlacing.Value == true then
            moveModel:Clone().Parent = workspace.PlacedItems
            if saving ==  nil then
                saving = {}
            end
            table.insert(saving, "Name = "..moveModel.Name.."["..game.Players.LocalPlayer.leaderstats["Item Data Store Name"].Value.."]".." and Position = ("..moveModel:FindFirstChild("Hitbox").Position.X..","..moveModel:FindFirstChild("Hitbox").Position.Y..","..moveModel:FindFirstChild("Hitbox").Position.Z..")")
            print("Name = "..moveModel.Name.."["..game.Players.LocalPlayer.leaderstats["Item Data Store Name"].Value.."]".." and Position = ("..moveModel:FindFirstChild("Hitbox").Position.X..","..moveModel:FindFirstChild("Hitbox").Position.Y..","..moveModel:FindFirstChild("Hitbox").Position.Z..")")
            wait(1)
        else
            wait()
            -- nil
        end
    end)
    itemname.Name = moveModel.Name
    itemname.Parent = workspace.PlacedItems
    if workspace.Tycoons.BasePlate.IsPlacing.Value == true then
        MoveItem()
    else
        repeat wait() until workspace.Tycoons.BasePlate.IsPlacing.Value == true
    end
end

The error would add more than 1 value to the "Item Data Store Name" And it is lines 36 (Loop) AND 39 (Adding more than 1 Value), Any help would be great..

0
When you point to a line please check the call stack and only give us the line with the error. There will only ever be one error outputted per script. As 39 is inside 36, 39 has the error. lukeb50 631 — 6y
0
Error also seems fairly obvious, as I doubt "Item Data Store Name" is a real object within your leaderstats lukeb50 631 — 6y

Answer this question