Hi, I'm attempting to create a build preview. Many of you probably know what I'm talking about but just in case let me explain. This script is supposed to check and see if the player has enough resources to build the wall, then if they do, take away the required resources and place a transparent version of the wall that follows your mouse until you click to place it again. I have finally gotten it to follow the players mouse now but when you click it doesn't place it down. Clicking does nothing it just continues to follow the mouse. Can someone please help me?
01 | GUI = script.Parent.Parent.Parent.Parent |
02 | Wall = game.ServerStorage.WoodWall |
03 | Player = game.Players.LocalPlayer |
04 | Mouse = Player:GetMouse() |
05 |
06 | script.Parent.MouseButton 1 Down:connect( function () |
07 | if Player.leaderstats.Wood.Value > = 5 then |
08 | Player.leaderstats.Wood.Value = Player.leaderstats.Wood.Value - 5 |
09 | GUI.Visible = false |
10 | WWall = Wall:Clone() |
11 | WWall.Parent = game.Workspace |
12 | WWall.Transparency = . 5 |
13 | end |
14 | end ) |
15 |
You keep trying to use "WWall" although you only defined "Wall". Besides that, the reason that the part is never placed is because you never disconnect the functions that continuously move the part. Setting WWall.Position does not permanently set its position.
Here's a quick example of lego-esque building in a localscript. Not FE.
01 | local player = game.Players.LocalPlayer |
02 | local mouse = player:GetMouse() |
03 | local blankPart = Instance.new( 'Part' ) |
04 | blankPart.Anchored = true |
05 | blankPart.CanCollide = false |
06 | blankPart.Transparency = 0.75 |
07 |
08 | while wait( 0.5 ) do |
09 | local part = blankPart:Clone() --never change the original part, only a clone |
10 | part.Parent = workspace |
11 | mouse.TargetFilter = part --ignore the clone while getting mouse position |
12 | local moveConn |
13 | moveConn = mouse.Move:connect( function () |
14 | local p = mouse.Hit.p |
15 | part.Position = Vector 3. new(math.floor(p.X),math.ceil(p.Y),math.floor(p.Z)) --mouse position in whole numbers |