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

I need help on making a place block tool? [Need Snapping Fix]

Asked by 5 years ago
Edited 5 years ago

I made this, but it's not FE, and it works without holding the tool, which I don't want. I want to be able to make this customizable for like a minecraft game.

Not Trying To Request, But I just cant get it to work.

I could make the blocks myself but i cant get it to connect to a folder in ServerStorage.

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local blankPart = Instance.new('Part')
blankPart.Anchored=true
blankPart.CanCollide=false
blankPart.Transparency=0.75

while wait(0.5) do
    local part = blankPart:Clone() --never change the original part, only a clone
    part.Parent=workspace
    mouse.TargetFilter=part --ignore the clone while getting mouse position
    local moveConn
    moveConn = mouse.Move:connect(function()
        local p = mouse.Hit.p
        part.Position = Vector3.new(math.floor(p.X),math.ceil(p.Y),math.floor(p.Z)) --mouse position in whole numbers
    end)
    mouse.Button1Down:wait() --do not have to connect a click function :)
    moveConn:disconnect() --stop moving the clone
    part.CanCollide=true
    part.Transparency=0
end

Please help, thanks (I will accept your answer if it works!) Also, I know F3X Exists, but I don't want to use that for this game, so don't send me plugin or model links for that, or broken toolbox models.

2 answers

Log in to vote
1
Answered by
sheepposu 561 Moderation Voter
5 years ago
Edited 5 years ago

I actually achieved the result you are looking for recently so I can help you. First off, the blocks can go in Replicated storage. Next, for a Minecraft type game, you should make a folder in the workspace called "Blocks" and have a server script in ServerScriptService do the following

game.Players.PlayerAdded:Connect(function(plr)
    Instance.new('Folder', workspace.Blocks).Name = plr.Name
end)

Then you can move all the blocks a player places into their folder which may come in handy later. You should get the mouse coords and everything and send it to a server script in ServerScriptService. If the block is placed from a LocalScript only the player who placed it will see the block. Also, if a localscript does all the math, it can be exploited by hackers. Here's a example of what your LocalScript might look like. I put a RemoteEvent in ReplicatedStorage called PlaceBlock. I also made another event called RemovePassive that will be used to remove passive blocks.

local mouse = game.Players.LocalPlayer:GetMouse()
local OriginalMousePosition = mouse.Hit.p
local Active = false
local tool = script.Parent

tool.Equipped:Connect(function()
    Active = true
end)

tool.Unequipped:Connect(function()
    game.ReplicatedStorage.RemovePassive:FireServer()
    Active = false
end)

mouse.Button1Down:Connect(function()
    if Active then
        game.ReplicatedStorage.PlaceBlock:FireServer(mouse.Hit.p, false) --Bool value represents passive bool
    end
end)

while wait() do
    if Active then
        if OrginalMousePosition ~= mouse.Hit.p then
            OrginalMousePosition = mouse.Hit.p
            game.ReplicatedStorage.RemovePassive:FireServer()
            game.ReplicatedStorage.PlaceBlock:FireServer(mouse.Hit.p, true) --Bool value represents passive bool
        end
    end
end

Here's what the server script in ServerScriptService would look like

local function IsInt(number) do
    if '.' in tostring(number) then return false else return true
end

local function NearestMultiple(number, multiple) --I think this function works
    number = math.floor(number)
    local newNum = number
    local count = 0
    while not IsInt(testNum/multiple) do
        newNum = testNum - 1
        count = count + 1
    end
    if count <= multiple/2 then
        return newNum
    else
        return newNum + multiple
end

game.ReplicatedStorage.PlaceBlock.OnServerEvent:Connect(function(plr, pos, passive)
    BlockName = --Get name of block
    local block = game.ReplicatedStorage.Blocks[BlockName]:Clone() --A folder called Blocks in ReplicatedStorage that contains all the blocks
    local BlockSize = block.Size.X --I can grab one value if all the values of the size are the same
    local x = NearestMultiple(pos.X, BlockSize) --Rounding the positions will give it a more Minecraft aspect
    local y = NearestMultiple(pos.Y, BlockSize)
    local z = NearestMultiple(pos.Z, BlockSize)
    block.Position = Vector3.new(x + _, y + _, z + _) --I'll leave you to fill in the blank. You have to add something so it centers rather than half being in the ground.
    if passive then
        block.Transparency = 0.5
        block.CanCollide = true
        block.Name = 'Passive'
    end
    block.Parent = workspace.Blocks[plr.Name]
end)

It should look something like this You can do the RemovePassive script, but let me tell you to use a "pcall(function()" in it, for when it is fired without there being a passive block. Hope this helps!

0
Does not work, see my below answer for more RobloxGameingStudios 145 — 5y
0
I got it to function RobloxGameingStudios 145 — 5y
0
Check my answer's comments for more info, on things i cant get to wrok RobloxGameingStudios 145 — 5y
0
mostly solved my issue, can u please help me on getting the building transparent thing that follow mouse, so its in a cube like form RobloxGameingStudios 145 — 5y
View all comments (2 more)
0
Any errors. It's the same as placing a black, but it's name is Passive, it is 50% transparent, and can't collide sheepposu 561 — 5y
0
Any errors. It's the same as placing a block, but it's name is Passive, it is 50% transparent, and can't collide sheepposu 561 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

You Fixed Most Of My Problems Through Comments, But I come across this error.

19:47:33.978 - ServerScriptService.New Server:2: 'then' expected near 'in'

local function IsInt(number) do
    if '.' in tostring(number) then return false else return true
end

This code seems to be broken, Also I don't understand what u mean by if '.' in, what am i supposed to fill in there?

0
The fill in the blank was BlockSize/2. Any errors? sheepposu 561 — 5y
0
I have no auto clicker on. I checked. RobloxGameingStudios 145 — 5y
0
It also goes through other blocks. RobloxGameingStudios 145 — 5y
0
also can u make the delete script, i cant seem to get it. RobloxGameingStudios 145 — 5y
View all comments (33 more)
0
Delete Passive? sheepposu 561 — 5y
0
Or delete a placed block? sheepposu 561 — 5y
0
I have the delete script, I just cant understand how to get the blocks to snap like minecraft so they aren't going through other blocks RobloxGameingStudios 145 — 5y
0
Oh, When you round them, you have to round them to a multiple of the size of the block. For example if the block is 5x5x5, then it should be rounded to the nearest multiple of 5. Let me fix the script to do it sheepposu 561 — 5y
0
Now instead of using math.floor, use the new function I added on my answer sheepposu 561 — 5y
0
check my answer for update RobloxGameingStudios 145 — 5y
0
please answer, PLEASE SO MUCH RobloxGameingStudios 145 — 5y
0
can u help RobloxGameingStudios 145 — 5y
0
can u help RobloxGameingStudios 145 — 5y
0
can u help RobloxGameingStudios 145 — 5y
0
can u help RobloxGameingStudios 145 — 5y
0
can u help RobloxGameingStudios 145 — 5y
0
can u help RobloxGameingStudios 145 — 5y
0
can u help RobloxGameingStudios 145 — 5y
0
can u help RobloxGameingStudios 145 — 5y
0
can u help RobloxGameingStudios 145 — 5y
0
can u help RobloxGameingStudios 145 — 5y
0
can u help RobloxGameingStudios 145 — 5y
0
can u help RobloxGameingStudios 145 — 5y
0
can u help RobloxGameingStudios 145 — 5y
0
can u help RobloxGameingStudios 145 — 5y
0
can u help RobloxGameingStudios 145 — 5y
0
can u help RobloxGameingStudios 145 — 5y
0
can u help RobloxGameingStudios 145 — 5y
0
can u help RobloxGameingStudios 145 — 5y
0
can u help RobloxGameingStudios 145 — 5y
0
can u help RobloxGameingStudios 145 — 5y
0
can u help RobloxGameingStudios 145 — 5y
0
can u help RobloxGameingStudios 145 — 5y
0
can u help RobloxGameingStudios 145 — 5y
0
can u help RobloxGameingStudios 145 — 5y
0
oh my RobloxGameingStudios 145 — 5y
0
ScriptingHelpers.Org glitch it seems RobloxGameingStudios 145 — 5y

Answer this question