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

[SOLVED] Using a script to place objects within a certain blocked out area?

Asked by 5 years ago
Edited 5 years ago

I don't have code for this yet since I'm not even entirely sure where to start. My goal here is to place an object on towards the back center of a 6x6x6 stud block no matter where the user clicks within that block to make the object appear.

For instance, I'd like a ladder to be placed towards the very back center of the area even if the user clicks the front or top or wherever of that area. How do I portion out blocks of areas that are 6x6x6 studs in a script? My entire map will be comprised of these 6x6x6 stud areas, so this is an integral part of the game that I'm not sure how to code.

Any ideas or pointers towards resources to get me started?

0
im pretty sure you have to use region3 or seomthing not sure WillBe_Stoped 71 — 5y
0
I thought that was just for terrain? Would it work with parts? Flannelling 4 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

You can make a region3 area, many examples of region3 are on youtube. After that, you just do math.random as position and use a parameter for the region3.

Ad
Log in to vote
0
Answered by 5 years ago

(Sorry in advance if formatting is weird, I tried) So, I managed to solve this issue without Region3 in a sort of interesting way that I thought would be worth noting on here. I used two local scripts, both of which are posted down below.

Essentially what I did was create a part named "REGION" that follows the player around to a new area every time they scoot themselves horizontally by 3 or -3 (since it's a 6x6x6 area). It follows horizontally in the Z direction as well as vertically in the Y direction. For visual purposes right now, the part is still visible, however, in the final game, it would be invisible to the player.

The second script is within a tool whose purpose is to place ladders when it clicks a block named "REGION". This ladder is placed towards the very back of the block in a spot where the user can access it easily (this is a platform style game, by the way, so rotation isn't taken into account here).

Here is the first script (the new script block thing really sucks, this took forever to paste in)

local player1 = script.Parent.Parent
local player = workspace:WaitForChild(player1.Name)
local part = Instance.new("Part",workspace)
part.Anchored = true
part.Name = "REGION"
part.CanCollide = false
part.Transparency = .5
part.BrickColor = BrickColor.new("Really red")
part.Size = Vector3.new(6,6,6)
part.CFrame = CFrame.new(-3,51,-3)
game:GetService("RunService").RenderStepped:Connect(function()
    local pos = player:FindFirstChild("Head").CFrame
    if pos.Z-part.Position.Z >= 3 then
        part.CFrame = CFrame.new(part.Position.X,part.Position.Y,part.Position.Z + 6)
    else if pos.Z - part.Position.Z <= -3 then
        part.CFrame = CFrame.new(part.Position.X,part.Position.Y,part.Position.Z - 6)
    end
    end
    if pos.y - part.Position.Y >= 4 then
        part.CFrame = CFrame.new(part.Position.X,part.Position.Y+6,part.Position.Z)
    else if pos.Y - part.Position.y <= -3 then
        part.CFrame = CFrame.new(part.Position.X,part.Position.Y-6,part.Position.Z)
    end
    end
end)

And here is the second script:

local ladder = game.workspace.LadderModel
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local tool = script.Parent
tool.Activated:Connect(function()
    if (workspace.Part.Position - script.Parent.Handle.Position).Magnitude < 10 then
        local part = workspace.Part
    end
    if mouse.Target ~= nil and mouse.Target.Name == "REGION" then
        local clone = ladder:Clone()
        clone.Parent = workspace
        clone:SetPrimaryPartCFrame(CFrame.new(mouse.Target.Position.X - 2,mouse.Target.Position.Y,mouse.Target.Position.Z))
    end
end)

Hope this is helpful to anyone trying to do something similar!

Answer this question