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

I'm trying to make a house system, but my script's not working or erroring, do you know why?

Asked by
epoke466 100
2 years ago

I used print() to find out where the script stops working and it is somewhere around line 34.

I know the script is long, but last time I posted no one answered. Please try to help me on this.

local Houses = workspace.Houses
local AvailableHouses = Houses.AvailibleHouses
local UsedHouses = Houses.UsedHouses

local DataStoreServide = game:GetService("DataStoreService")
local PlayerCarsDataStore = DataStoreServide:GetDataStore("ChosenCar")
local CurrentFurnature = DataStoreServide:GetDataStore("CurrentFurnature")
local FurnatureAnchor = DataStoreServide:GetDataStore("FurnatureAnchor")
local DefaultCar = "Sedan (red)"

game.Players.PlayerAdded:Connect(function(Player)
    local ChosenHouse = AvailableHouses:FindFirstChildOfClass("Folder")
    print("A")
    ChosenHouse.Name = Player.Name
    print("A")
    ChosenHouse.Parent = UsedHouses
    print("A")
    local Charachter = workspace:WaitForChild(Player.Name)
    print("A")
    Charachter:MoveTo(ChosenHouse.Spawn.Position)
    print("A")
    local playerFurnature = CurrentFurnature:GetAsync(Player.UserId) or nil
    print("A")
    if playerFurnature ~= nil then
        playerFurnature = game:GetService("HttpService"):JSONDecode(playerFurnature)
        print("A")
    else
        playerFurnature = nil
        print("A")
    end
    local furnatureModel = Instance.new("Model", ChosenHouse.Furnature)
    print("A")
    furnatureModel.Name = "FurnatureGroup"
    print("A")
    if playerFurnature ~= nil then
        print("A")
        for key, value in pairs(playerFurnature) do
            print("A")
            local createdItem = game.ReplicatedStorage.Furniture:WaitForChild(key):Clone()
            print("A")
            createdItem.Parent = furnatureModel
            print("A")
            createdItem.CFrame = CFrame.new(value)
            print("A")
        end
        print("A")
        local anchorValues = FurnatureAnchor:GetAsync(Player.UserId) or nil
        print("A")
        if anchorValues ~= nil then
            local createdAnchor = Instance.new("Part", furnatureModel)
            createdAnchor.Anchored = true
            createdAnchor.Name = "Anchor"
            createdAnchor.Position = anchorValues.Position
            createdAnchor.Orientation = anchorValues.Orientation
            createdAnchor.Size = anchorValues.Size
            createdAnchor.Shape = Enum.PartType.Ball
            createdAnchor.Transparency = 1
            createdAnchor.CastShadow = false
            createdAnchor.CanCollide = false
            furnatureModel.PrimaryPart = createdAnchor
            furnatureModel:MoveTo(ChosenHouse.FurnaturePosition.Position)
            furnatureModel:PivotTo(ChosenHouse.FurnaturePosition.CFrame)
        else
            local createdAnchor = ChosenHouse.FurnaturePosition:Clone()
            createdAnchor.Name = "Anchor"
            createdAnchor.Parent = furnatureModel
            furnatureModel.PrimaryPart = createdAnchor
            furnatureModel:MoveTo(ChosenHouse.FurnaturePosition.Position)
            furnatureModel:PivotTo(ChosenHouse.FurnaturePosition.CFrame)
        end
    end

    game.ReplicatedStorage.Change.OnServerEvent:Connect(function(player, part, color)
        if part == "Wall" then
            for i, part in pairs(ChosenHouse.Wall:GetChildren()) do
                part.Color = color
                wait()
            end
        else
            for i, part in pairs(ChosenHouse.Trim:GetChildren()) do
                part.Color = color
                wait()
            end
        end
    end)
    Player.CharacterAdded:Connect(function(Char)
        Char:MoveTo(ChosenHouse.Spawn.Position)
    end)
    game.Players.PlayerRemoving:Connect(function(player)
        local FG = ChosenHouse.Furnature.FurnatureGroup
        print("A")
        local Anchor = FG:WaitForChild("Anchor")
        print("A")
        local AnchorProperties = {
            Position = nil,
            Orientation = nil,
            Size = nil,
        }
        print("A")
        AnchorProperties.Position = Anchor.Position
        print("A")
        AnchorProperties.Size = Anchor.Size
        print("A")
        AnchorProperties.Orientation = Anchor.Orientation
        print("A")
        script.Parent.HouseSave.Event:Fire(Player.UserId, AnchorProperties)
        print("A")
        Anchor:Destroy()
        print("A")
        local SavingItems = {}
        print("B")
        for i, item in pairs(FG:GetChildren()) do
            print(tostring(item.Value.Value))
            SavingItems[item.Name] = tostring(item.Value.Value)
            print("ItemSaved")
        end
        print("All items saved")
        print(SavingItems)
        local EncodedSavedItems = game:GetService("HttpService"):JSONEncode(SavingItems)
        print(EncodedSavedItems)
        CurrentFurnature:SetAsync(Player.UserId, EncodedSavedItems)
        if player == Player then
            ChosenHouse.Name = "OpenHouse"
            ChosenHouse.Parent = AvailableHouses
            end
        end)
    game.ReplicatedStorage.SpawnCar.OnServerEvent:Connect(function()
        local CarName = PlayerCarsDataStore:GetAsync(Player.UserId) or DefaultCar
        local Car = game.ReplicatedStorage.Cars:FindFirstChild(CarName):Clone()
        Car.Parent = workspace
        Car:MoveTo(ChosenHouse.CarSpawn.Position)
    end)
end)

Answer this question