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.
Nice tutorial, but it’s good to show how to make angle calculation, you can use cframe.lookat():toorientation() it’s very usefull to get 3 axis, if you wan’t world space then add :toworldspace before toorientation
yea, i love rts games, and i wanted to make one, but i’m too lazy xd,but anyways, make more tutorials like this, because old players of roblox don’t much like clickers as i know, soo this games are engaging, i worked with vectors soo remotes ect. is kind of meh for me , but maybe one day i’ll make game.
and one thing more, why you made soo complicated movement, you can use humanoid, i know it’s laggy, or use simply tweens, or body velocity and gyro - this will be the best option, for example TC3 have this like movement as i know, because it have collisions and it’s easy to make, moreover you making one big mistake, if position = position, this don’t works everytime, especially when you have multiple units and positions can be … soo better is to detect near magnitude like 0.1, it’s always safe, i used body gyro and velocity to make animals for game, and this worked, collision groups can be helpfull with this, and i know this can be messy and anchored parts are better.
it’s maybe deprecated, but it works, and body velocity is deprecated too, i know using deprecated things are bad blah blah blah, but many games using it, body gyro is the best for that, align orientation aren’t as good as it, soo you can use it, and it’s don’t broken if you know how to use it, i used it to rotate player in weapon system (third person system) and it’s the easiest and the best. Old things sometimes is the best
I think velocity works fine, but playing Medieval RTS i kinda noticed that when there’s a lot of units moving in the map, the movement system starts lagging which makes the units move slower, I don’t know if this problem is caused by the linear velocity, but it could be.