(Still need help) How can I have a local do 2 actions?

I want to try and make a smooth building block mechanic tool; Like in Roblox skywars.

I have a issue trying to make it so you can easily bridge at ease, like this.
Screen Recording (5-27-2021 9-03-46 PM).wmv (1.8 MB)
But it’s been going like this…
rec.WMV (6.1 MB)
I’ve been trying local prefixes to get a 12 x 12 block (Named Bridge) to place down below the dirt (Named FakePart), and it’s very hard to make a clone of Bridge below the dirt. Can anyone tell me how to fix this script so two locals can conjoint?

 game.ReplicatedStorage.Events.PlaceBlock.OnServerEvent:connect(function(plyr, ncf, target)
	if player then -- Dont worry about "blocks", its just a variable.
		if player.Name == plyr.Name then
			if blocks then
				if blocks.Value > 0 then
					if target.Parent then
						blocks.Value = blocks.Value - 1
						script.Parent.Handle.Place:Play()
						script.Parent.Displayer.SGui.Detail.Text = blocks.Value
						local np = game.ReplicatedStorage.FakePart:Clone() -- This part are what I'm really worried about
						np.CanCollide = true -- These parts are what I'm worried about
						np.CFrame = ncf -- These parts are what I'm worried about
						np.Name = 'Dirt'  -- These parts are what I'm worried about
						local pskin = game.ReplicatedStorage.PlayerSkins:FindFirstChild(plyr.Name)
						if pskin then
							if pskin.Value ~= "Default" then
								for _,v in pairs (np:GetChildren()) do
									if v:IsA("Texture") then
										v.Texture = "rbxassetid://" .. pskin.Value
									end
								end
							end
						end
						if target.Parent.Name ~= 'WoodTrunk' and target.Parent.Name ~= 'GrassBlock' and target.Parent.Name ~= 'BronzeOre' and target.Parent.Name ~= 'GoldOre' and target.Parent.Name ~= 'DiamondOre' then
							np.Parent = target.Parent
						else
							np.Parent = target.Parent.Parent
						end
						
						game.Debris:AddItem(np, 200)
					end
				end
			end
		end
	end
end)

So can anyone help me to add another local to the area where it says

– This part is what I’m really worried about

Thanks!
If you need more explanation, just ask!

1 Like

I dont really understand what you want to begin with tbh.

Can you please explain more? It’s hard to understand.

So basically, How can i have a local do 2 actions?
By in local, i mean
local Example = game.Workspace.Example.Example.
I want a local To do 2 actions. Need more explanation? Ask!

Uhmm just use coroutines dude.

Okay! So what i want is, how can i have a local do 2 actions?
By in local, i mean like in a script
local Example = game.Workspace.Example.Example.
I want a local To do 2 actions. Need more explanation? Ask!

Whats coroutines? Im a beginner scripter and need help and don’t know a bunch of stuff. And im not sure if thats in lua.

Use the mouse’s hit cframe and math to get the edge of the block(mouse.target) the cursor is nearest too, then check if theres an open space in that direction next to it and if there is, place the block

you may also want to check the distance to the center of the top surface for stacking

Mouse.Hit (roblox.com)
Mouse.Target (roblox.com)
Player:GetMouse (roblox.com)

1 Like

Basically what you need like lets say you are in a while loop and you want to execute some code whenever a value is set to true but you cant so that cuz you are in a while loop right? To do that we use coroutines. Lemme give you an example.
Btw im on mobile rn so it will take sometime for me to write.

local val = false

local function CorFunc() 
    While true do
        wait(2)
        if val == true then
            --code the stuff thats gonna happen while the while loop goes on. 
        end
    end
end
local cor = coroutine.create(CorFunc)
coroutine.resume(cor)

while true do
    -- other code that goes on
end

Note: You should not use this as i wrote this for example, i’d say research and learn coroutines and then look at this exapmle

1 Like

Thank you!, Ill find this useful while building.

Thats very similar but not what i need. I already have a solution, Thanks for helping!

I’d still suggest that you learn it as it is sometimes needed.

1 Like

Ill use it at sometimes, Thanks!

but also, How do i get the nearest block? Do i need to do a cframe script?

I dont know how your block system works but if it has a grid you could do targetIndex + 1 in the direction but if thats not how your system works then you can raycast starting from the target block origin into the direction you want with the length of the ray as (block size/2) + 1

Script examples? I don’t understand due to me being a noobie at coding.

Or is that not allowed, I dont know.

The origin is already half the length so one more half = full then do full length + 1


WorldRoot:Raycast (roblox.com)
CFrame (roblox.com)
How does LookVector work? - Help and Feedback / Scripting Support - DevForum | Roblox

1 Like