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

Placement script not recognizing that there are multiple baseplates?

Asked by 6 years ago
Edited 6 years ago

I have this placement system script and, it works great until I want it to recognize that there are multiple baseplates, I do this by creating a table off all baseplates then getting the table.

But it doesnt really work and I dont know why it doesnt work.

https://gyazo.com/cf77d1f1838d5701bae061cacdd55825

There is a video so like what happens is, it clones a model to where your placing and it also clones one to every baseplate, like in the house you see how that one is cloned but its not supposed to be there.

But anyways heres my ClientScript, it requires a module script. If you need the module script for more info just ask and ill post it, but beware its alot of code.

ClientScript

wait(5)
print("PlacementStarted")
local PlacementHanlder = require(script:WaitForChild("PlacementModule"))

local AllBaseplates = {}

function UpdateBaseplateData()
    AllBaseplates = {}
    for i,v in pairs(workspace.Base:GetDescendants()) do
        if v.Name == "Baseplate" then
            table.insert(AllBaseplates, v)
            for j,m in pairs(AllBaseplates) do
                local Base = m
                local Items = game:GetService("ReplicatedStorage").Items
                local Player = game.Players.LocalPlayer
                local CraftingGui = Player.PlayerGui.ScreenGui:WaitForChild("PlayerCrafting")
                local ReplicatedStorage = game:GetService("ReplicatedStorage")
                local Plane = PlacementHanlder.new(Base, workspace.Base.ItemHolder, 1)

                local Model
                local Signal
                local CurrentItemName   

                local function CancelPlacement()
                    if (CurrentItemName) then
                        Plane:disable()

                    if (Model.Parent) then
                        Model:Destroy()
                    end

                        Model = nil
                        Signal = nil
                        CurrentItemName = nil       

                    end
                end

                local function InitiatePlacement(ItemName)
                    CancelPlacement()

                    Model = Items[ItemName]:Clone()

                    CurrentItemName = ItemName  

                    for _, object in pairs(Model:GetChildren()) do 
                        if object:IsA("BasePart") then
                            object.CanCollide = false
                        end
                    end

                    Model.Parent = workspace.CurrentlyPlacing

                    local Signal = Plane:enable(Model)

                    Signal:Connect(function(Location, _)
                        game:GetService("ReplicatedStorage").ClientPlaced:FireServer(CurrentItemName, Location[1])      

                        CancelPlacement()
                    end)
                end

                local function BeginPlacement()
                    if script.Parent.EnablePlacement.Value == true then
                        print("PlacementMyDude")
                        InitiatePlacement(CraftingGui.Info.ItemName.Text)
                        wait(3)
                        script.Parent.EnablePlacement.Value = false
                    end
                end

                script.Parent.EnablePlacement.Changed:Connect(BeginPlacement)
            end
        end
    end
end

UpdateBaseplateData()
workspace.Base.ChildAdded:Connect(UpdateBaseplateData)
workspace.Base.ChildRemoved:Connect(UpdateBaseplateData)

workspace.Base.ItemHolder.ChildAdded:Connect(UpdateBaseplateData)
workspace.Base.ItemHolder.ChildRemoved:Connect(UpdateBaseplateData)

Thanks and hopefully we can figure this out, I was supposed to get my game out today but then this happened so im kinda bummed out now.

Answer this question