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

Why isn't lookvector working properly?

Asked by 5 years ago
Edited 5 years ago

I have the following scripts to save and load players bases:

Join Script(server script):

if Table[2] ~= nil and Table[2][1] ~= nil then --Look below for table models save in
    local models = Table[2]
    local modelData = models[1]
    for _, modelData in pairs(models) do
        local targetModel = modelData.ModelName
        local information = modelData.Position
        local newModel = items:FindFirstChild(targetModel):Clone()
        local position = bases:FindFirstChild(teamname).Floor.CFrame * Vector3.new(information[1], information[2], information[3])
        local lookVector = Vector3.new(information[4], information[5], information[6])
        newModel:SetPrimaryPartCFrame(CFrame.new(position, position + (lookVector * 5)))
        newModel.Parent = bases:FindFirstChild(teamname).ItemHolder
    end
else
    print((plr.Name).." has no base")
end

Leave Script(server script):

local models = {}
for _, model in pairs(bases:FindFirstChild(teamname).ItemHolder:GetChildren()) do
    local modelData = {}        
    local primaryPart = model.PrimaryPart
    local position = bases:FindFirstChild(teamname).Floor.CFrame:inverse() * primaryPart.Position
    local direction = primaryPart.CFrame.lookVector 
    modelData.ModelName = model.Name
    modelData.Position = {position.X, position.Y, position.Z, direction.X, direction.Y, direction.Z}
    models[#models + 1] = modelData
end
local MainLeave = {moneyLeave.Value, models, InvItems} --Focus on models here
datastore:SetAsync(plr.UserId, MainLeave)

The problem is that the look vector appears not to be working here is a picture displaying what happens when you load into another base.

http://imgur.com/a/ZCMkSMX

As you can see ^ if you save your base in a plot, it wont load with the correct look vector.

This is what i want:

http://imgur.com/a/jAffEgP

Anyone have any sugestions? Any reasons lookvector isn't working?

0
First, lookVector is deprecated, use LookVector. Second, you shouldn't be defining variables as 'lookVector' or 'LookVector', they can get confusing. oilsauce 196 — 5y

Answer this question