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

[Solved by Me]How do I make a build script with a Plot?

Asked by 3 years ago
Edited 3 years ago

I made this build script, but it won't work and i am not getting any errors, what suppose to happen is 1.wait until the GUI is pressed 2.Make a clone of the model 3.Make the clone follow the mouse 4.test if the player wants to place the object in the plot 5.makes another clone and place it where the player wants to put it

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local ReinforcedIronWall = game.Workspace.BluePrintWalls.ReinforcedIronWall

---------------------------------------------------------------------

local function round (n)
    return math.floor(n + 0.5)
end

---------------------------------------------------------------------

local uis = game:GetService("UserInputService")
      uis.InputBegan:Connect(function(a,b)

    if not b 

    then if a.KeyCode == Enum.KeyCode.R then
           ReinforcedIronWall:SetPrimaryPartCFrame(ReinforcedIronWall.PrimaryPart.CFrame * CFrame.Angles(0,math.rad(90),0))
        end
    end
end)

---------------------------------------------------------------------

script.Parent.MouseButton1Click:Connect(function()
    local CloneReinforcedIronWall = ReinforcedIronWall:Clone()
          CloneReinforcedIronWall.Parent = game.Workspace.ClonedObjects
          CloneReinforcedIronWall.Name = "ClonedReinforcedIronWall"
    local ClonedReinforcedIronwall = game.Workspace.ClonedObjects.ClonedReinforcedIronWall
    mouse.TargetFilter = game.Workspace.ClonedObjects:WaitForChild("ClonedReinforcedIronWall")
    mouse.Move:Connect(function()
    CloneReinforcedIronWall:SetPrimaryPartCFrame(CFrame.new(round(mouse.Hit.Position.X),round(mouse.Hit.Position.Y),round(mouse.Hit.Position.Z)) + Vector3.new(0,5,0))

    mouse.Button1Down:Connect(function()

    local ObjectX = CloneReinforcedIronWall.Primarypart.Position.X
    local ObjectX = CloneReinforcedIronWall.Primarypart.Position.X
    local ObjectY = CloneReinforcedIronWall.Primarypart.Position.Y
    local ObjectY = CloneReinforcedIronWall.Primarypart.Position.Y
    local ObjectZ = CloneReinforcedIronWall.Primarypart.Position.Z
    local ObjectZ = CloneReinforcedIronWall.Primarypart.Position.Z
if 
    ObjectX < game.Workspace.Plot.Position.X - 150 == true and 
    ObjectX > game.Workspace.Plot.Position.X + 150 == true and
    ObjectY > game.Workspace.Plot.Position.Y == true and
    ObjectY < game.Workspace.Plot.Position.Y + 1500 == true and 
    ObjectZ < game.Workspace.Plot.Position.Z + 150 == true and
    ObjectZ > game.Workspace.Plot.Position.Z + 150 == true 
then
    local BluePrint = game.Workspace.ClonedObjects.ClonedReinforcedIronWall.Primarypart.Position
    local PlacingObject = game.Workspace.Walls.ReinforcedIronWall:Clone()
          PlacingObject:SetPrimaryPartCFrame(CFrame.new(BluePrint))
          PlacingObject.Parent = game.Workspace.PlacedObjects

            end
        end)
    end)
end)    

---------------------------------------------------------------------

please help, i don't understand why it wont work because i can't make it to work.Thank you in advance

1 answer

Log in to vote
0
Answered by 3 years ago

i made the build script now, i'm just working on the collision part so what i done is when the part is not on top of the plot i just set an anchor Position so its anchor to that position until the mouse.hit .position is equal to the top of the plot and i added offset so all parts of the model is above the part

this script works for models it also makes a semi transparent blueprint, it also has destroy mode so it would destroy the model it works by pressing right click and pressing left click on the model and right click again to go back to build mode, and just click to build, it has changeable grid too. This script is not done yet, i'm making it so scroll wheel goes through the build selection and more stuff

local Player = game.Players.LocalPlayer
local char = Player.Character or Player.CharacterAdded:Wait()
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local Mouse = Player:GetMouse()
local Gridsize = 1
local Model = game.Workspace.Conveyor
local ModelPrimaryPart = Model.PrimaryPart

local Plot = game.Workspace.Plots.Plot
local HalfSizeforX = Plot.Size.X/2
local HalfSizeforZ = Plot.Size.Z/2
local Heightlimit = 100

local PosX
local PosY
local PosZ

local AngleY = math.rad(0)
local RotationState = 1

local ModelCloneBluePrint = Model:Clone()
ModelCloneBluePrint.Parent = game.Workspace
ModelCloneBluePrint.Name = ModelCloneBluePrint.Name.."BluePrint"
local ModelCloneBluePrintChildren = ModelCloneBluePrint:GetDescendants()
for index,value in pairs(ModelCloneBluePrintChildren) do
    if not value:IsA("Model")
    then
        value.Transparency = 0.5
        value.CanCollide = false
        if value.Name == "PrimaryPart" or value.Name == "TouchDeny"
        then value.Transparency = 1 
        end 
    end
end

UserInputService.InputBegan:Connect(function(key)
    if key.KeyCode == Enum.KeyCode.R then
        RotationState = RotationState + 1
        AngleY = AngleY + math.rad(45)
        if AngleY == math.rad(360) then
            AngleY = math.rad(0)
            RotationState = 1
        end
    end
end)

local DestroyMode = false
RunService.RenderStepped:Connect(function()
    if DestroyMode == false
    then
        Mouse.TargetFilter = ModelCloneBluePrint

        PosX  = math.floor(Mouse.Hit.X / Gridsize + 0.5) * Gridsize
        PosY  = math.floor(Mouse.Hit.Y / Gridsize + 0.5) * Gridsize
        PosZ  = math.floor(Mouse.Hit.Z / Gridsize + 0.5) * Gridsize

        local ModelXOffset = ModelPrimaryPart.Size.X/2
        local ModelYOffset = ModelPrimaryPart.Size.Y/2
        local ModelZOffset = ModelPrimaryPart.Size.Z/2

        if RotationState == 1 or RotationState == 3 then
            HalfSizeforX = Plot.Size.X/2 - ModelXOffset
            HalfSizeforZ = Plot.Size.Z/2 - ModelZOffset
        elseif RotationState == 2 or RotationState == 4 then
            HalfSizeforX = Plot.Size.X/2 - ModelZOffset
            HalfSizeforZ = Plot.Size.Z/2 - ModelXOffset
        end 

        local BorderPosX = Plot.Position.X + HalfSizeforX
        local BorderNegX = Plot.Position.X - HalfSizeforX
        local BorderCelY = Plot.Position.Y + Heightlimit
        local BorderFlrY = Plot.Position.Y
        local BorderPosZ = Plot.Position.Z + HalfSizeforZ
        local BorderNegZ = Plot.Position.Z - HalfSizeforZ

        if PosX > BorderPosX then
            PosX = BorderPosX
            PosY = BorderFlrY 
        elseif PosX < BorderNegX then
            PosX = BorderNegX
            PosY = BorderFlrY 
        end

        if PosZ > BorderPosZ then
            PosZ = BorderPosZ
            PosY = BorderFlrY 
        elseif PosZ < BorderNegZ then
            PosZ = BorderNegZ
            PosY = BorderFlrY 
        end
        local ModelPrimaryPart = ModelCloneBluePrint.PrimaryPart
        local ModelPoint1 = ModelPrimaryPart.Size/2 + ModelPrimaryPart.Position
        local ModelPoint2 = ModelPrimaryPart.Size/2 - ModelPrimaryPart.Position
        local ModelRegion = Region3.new(ModelPoint1,ModelPoint2)
        local Obstacle = workspace:FindPartsInRegion3WithIgnoreList(ModelRegion,char,math.huge)
        for i,v in pairs(Obstacle) do
            local Obstacles = v.Parent
            local ObstaclePrimaryPart = v.PrimaryPart
            local ObstacleSize
        end

        PosY = PosY + ModelYOffset
        ModelCloneBluePrint:SetPrimaryPartCFrame(CFrame.new(PosX,PosY,PosZ) * CFrame.Angles(0,AngleY,0))
    else
        ModelCloneBluePrint:SetPrimaryPartCFrame(CFrame.new(0,10000,0))
    end
end)

Mouse.Button1Down:Connect(function()
    if DestroyMode == false
    then
        local Clone = Model:Clone()
        Clone.Parent = game.Workspace.PlacedObject
        Clone.Name = Model.Name .."Clone"
        Clone:SetPrimaryPartCFrame(CFrame.new(ModelCloneBluePrint.PrimaryPart.Position) * CFrame.Angles(0,AngleY,0))
        local TouchDenySize = Clone.TouchDeny.Size
        local TouchDenySizeX = TouchDenySize.X + ModelPrimaryPart.Size.X
        local TouchDenySizeY = TouchDenySize.Y
        local TouchDenySizeZ = TouchDenySize.Z + ModelPrimaryPart.Size.Z
        Clone.TouchDeny.Size = Vector3.new(TouchDenySizeX,TouchDenySizeY,TouchDenySizeZ)
    elseif Mouse.Target.Parent.Parent == game.Workspace.PlacedObject 
    then Mouse.Target.Parent:Destroy()
    end
end)

Mouse.Button2Down:Connect(function()
    DestroyMode = not DestroyMode
end)
0
for those who wanna use this all you have to set up is the model and primarypart spectacularnicknack 2 — 3y
0
i just remember this site so i made the answer when i returned here spectacularnicknack 2 — 3y
Ad

Answer this question