Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

How would I recreate a building tool that can place blocks?

Asked by 1 year ago

Greetings fellow scripters, I'm here today wondering how I can make a building tool like stamper build, but to place blocks in FE. My goal is to recreate build to survive zombies, with old roblox materials as textures. Why I want to make this game is because it was a really good game back in the time. Anyways, here is my script. It can't use the Z; most likely because I haven't explored a certain thing required for me for this script.

Tool:

script.Parent.Activated:Connect(function()

local mouse = game.Players.LocalPlayer:GetMouse()

local X = mouse.X

local Y = mouse.Y

local Z = mouse.Z

print(X,Y)

game.ReplicatedStorage.BuildObject:InvokeServer(X,Y)

end)

ServerScriptService:

game.ReplicatedStorage.BuildObject.OnServerInvoke = function(X,Y)

local block = Instance.new("Part",workspace)

block.Size = Vector3.new(4,4,4)

block.BrickColor = BrickColor.new("Brown")

local t1 = Instance.new("Texture",block)

local t2 = Instance.new("Texture",block)

local t3 = Instance.new("Texture",block)

local t4 = Instance.new("Texture",block)

local t5 = Instance.new("Texture",block)

local t6 = Instance.new("Texture",block)

t1.Texture = "rbxassetid://155806200"

t2.Texture = "rbxassetid://155806200"

t3.Texture = "rbxassetid://155806200"

t4.Texture = "rbxassetid://155806200"

t5.Texture = "rbxassetid://155806200"

t6.Texture = "rbxassetid://155806200"

t1.Face = "Front"

t2.Face = "Back"

t3.Face = "Bottom"

t4.Face = "Top"

t5.Face = "Left"

t6.Face = "Right"

block.Position = Vector3.new(X,Y,0)

end

I'm quite sorry for the messy code above.

1 answer

Log in to vote
1
Answered by
A_thruZ 29
1 year ago

One reason it might be is because you are using Mouse.X , Mouse.Y, and Mouse.Z. To fix the problem with the Z, is to change each of them to Mouse.Hit.p.X, Mouse.Hit.p.Y, and Mouse.Hit.p.Z. Or otherwise, you can just erase X, Y, and Z and use Mouse.Hit.p for the whole set of 3 arguments, since Mouse.Hit.p returns a Vector3 Value.

So now, for the whole Drag'n'Drop the pieces system, you can create a new variable, called Target. Then you can create code to set the Target to mouse.Target when the mouse presses down on an object, and then sets Target to nil when releasing. Simply using mouse.Target doesn't work, since eventually the player might move their mouse too fast, and end up dropping the piece. Using a variable, will make the piece the same one the player starts dragging, and Target will stay until the player lets go of their mouse, so from a LocalScript, you could try this: local player = game.Players.LocalPlayer local mouse = player:GetMouse() local target = nil mouse.Button1Down:Connect(function() if mouse.Target then if mouse.Target.Locked == false and mouse.Target.Anchored == false then target = Mouse.Target end end end) mouse.Button1Up:Connect(function() if target then target = nil end end) while true do target.Position = Mouse.Hit.p end

0
Ill be sure to try, thanks. :D User#22722 20 — 1y
Ad

Answer this question