This system is quite outdated, a lot of knowledge is required in order to make this efficient!
Step 1:
Get the premade unit model from this link to get started: https://www.roblox.com/library/12130875696/Unit
- Put it in a folder called “Units”
Step 2:
Create two remote events named “CreateBeam” and “MoveUnit” in ReplicatedStorage
Step 3:
Create a script named “UnitMove” in ServerScriptService
Then open it and begin writing!
-
Declare positions as we’ll be using tables to store unit positions.
-
Then we make the “MoveUnit” remote event function. Add three parameters “player”, “hitpos”, “unit”.
-
Declare loop to true, it’ll be used to stop the following loop.
-
Create a table referenced to the unit and put hitpos inside of it.
-
Fire a client event which will create a beam. Add three parameters “player”, positions[unit][1], “unit”, “false”.
-
Create a while loop which constantly check whether youve reached the destination or not.
-
if unit still exists after the loop is done, stop the unit and remove the beam.
-
This script is done!
Step 4:
Create two local scripts named: “Selection” and “UnitMoveHelper”
Then open “Selection” and begin writing.
-
Declare two variables “player” and “Mouse”
-
Create a function if the Mouse1Button is clicked.
-
If Mouse.Target doesn’t equal nil then proceed to check if it’s in game.Workspace.Units.
-
If the unit isn’t selected then select otherwise unselect.
Step 5:
Open the local script that we created earlier named “UnitMoveHelper”
-
Declare two variables “player” and “Mouse”.
-
Create a function if the Mouse1Button is clicked.
-
Once clicked, get all units that are selected and fire a server remote that would move the unit to Mouse.Hit.Position
Step 6:
In the same script as before we make the “CreateBeam” function
-
If the parameter destroy is false then continue to make a beam, otherwise destroy the beam.
-
Copy it from below.
OnClientEvent function
game.ReplicatedStorage.CreateBeam.OnClientEvent:Connect(function(hitpos, unit, destroy)
--// check whether to destroy or create the beam
if destroy == false then
if unit.Parent then
if not unit.PrimaryPart:FindFirstChild("Beam") then
--// create an attachment
local attachment = Instance.new("Attachment")
attachment.WorldPosition = hitpos
attachment.Name = "AttBeam"
attachment.Parent = unit.Ignore
--// create a beam
local beam = Instance.new("Beam")
beam.Color = ColorSequence.new(Color3.fromRGB(255, 255, 255),Color3.fromRGB(255, 144, 146))
beam.Width0 = 0.2
beam.Width1 = 0.2
beam.FaceCamera = true
beam.Attachment0 = unit.PrimaryPart.Att
beam.Attachment1 = attachment
beam.Parent = unit.PrimaryPart
else
--// if there's already a beam:
local attachment = Instance.new("Attachment")
attachment.WorldPosition = hitpos
attachment.Name = "AttBeam"
attachment.Parent = unit.Ignore
unit.PrimaryPart:FindFirstChild("Beam").Attachment0 = unit.PrimaryPart.Att
unit.PrimaryPart:FindFirstChild("Beam").Attachment1 = attachment
end
end
else
--// destroy beam and attachment
if unit.PrimaryPart:FindFirstChild("Beam") then
unit.PrimaryPart:FindFirstChild("Beam"):Destroy()
end
for i,v in pairs(unit.Ignore:GetChildren()) do
if v.Name == "AttBeam" then
v:Destroy()
end
end
end
end)
Experiencing Issues?
-
Launch the game with the Output bar and look for errors.
-
If you have questions then reply to this topic.
Final Result:
You must polish the scripts provided above, as they’re not supposed to be final.