local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(Character)
local start = Instance.new("Attachment")
start.Name = "start"
start.Parent = Character:WaitForChild("HumanoidRootPart")
local Beam = Instance.new("Beam")
Beam.Name = "Beam"
Beam.Parent = workspace
Beam.Texture = "rbxassetid://136011733"
Beam.TextureLength = 6
Beam.TextureMode = "Wrap"
Beam.TextureSpeed = 0.8
Beam.FaceCamera = true
Beam.Attachment0 = start
Beam.Attachment1 = game.Workspace.Part1.Attachment1
Beam.Color = ColorSequence.new(Color3.fromRGB(0,255,0),Color3.fromRGB(255,0,0))
Beam.Width0 = 3
Beam.Width1 = 3
end)
end)
Here you go. For some reason The "start" attchment didn't want to be a parent of the lower torso. So I had to change it to HumanoidRootPart. Also, Beam.Color uses a color sequence. So you can't use brick colors for it.
Edit: If you only want one person to see the beams you should use local scripts.
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local start = Instance.new("Attachment")
start.Name = "start"
start.Parent = HumanoidRootPart
local Beam = Instance.new("Beam")
Beam.Name = "Beam"
Beam.Parent = workspace
Beam.Texture = "rbxassetid://136011733"
Beam.TextureLength = 6
Beam.TextureMode = "Wrap"
Beam.TextureSpeed = 0.8
Beam.FaceCamera = true
Beam.Attachment0 = start
Beam.Attachment1 = game.Workspace.Part1.Attachment1
Beam.Color = ColorSequence.new(Color3.fromRGB(0,255,0),Color3.fromRGB(255,0,0))
Beam.Width0 = 3
Beam.Width1 = 3
Note that if you put the script inside game.StarterPlayer.StarterPlayerScripts the beam will stop once you die. It will not reset. But if you put it inside of StarterGui it will. The reason is because StarterGui reloads its children everytime you spawn.
Edit 2:
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local Active = game.Workspace.PartActive
local invs = game.Workspace.PartInvs
local start = Instance.new("Attachment")
start.Name = "start"
start.Parent = HumanoidRootPart
local Beam = Instance.new("Beam")
Beam.Name = "Beam"
Beam.Parent = workspace
Beam.Texture = "rbxassetid://136011733"
Beam.TextureLength = 6
Beam.TextureMode = "Wrap"
Beam.TextureSpeed = 0.8
Beam.FaceCamera = true
Beam.Attachment0 = start
Beam.Attachment1 = game.Workspace.Part1.Attachment1
Beam.Color = ColorSequence.new(Color3.fromRGB(0,255,0),Color3.fromRGB(255,0,0))
Beam.Width0 = 3
Beam.Width1 = 3
Active.Touched:Connect(function(player)
local Humanoid = player.Parent:FindFirstChild("Humanoid")
if Humanoid then
Beam.Enabled = true
end
end)
invs.Touched:Connect(function(player)
local Humanoid = player.Parent:FindFirstChild("Humanoid")
if Humanoid then
Beam.Enabled = false
end
end)
There are multiple ways to do this but this is the way I chose to approach the issue. This isn't ideal since it goes against the DRY-principle but it at least works. Also, I want to clarify that both "Active" and "Invs" are parts that I've put in the workspace. They are not the same part as Part1. These are separate parts.
The reason I check if the part that touched contains a humanoid is because the touched event fires whenever anything touches it. So while it's on the ground the touched event will fire a lot of times without you even being near it.
Hope that clarifies it.
8 comments
Dude, it work, really THANKS !
No problem dude : ) Also, I hate to ask but can you upvote me please? I really need it to get to the next rank. Thankies!
Sorry I can't upvote because I don't have 25 reputation. I also have a question: how to make for the beam to being see by one player ?
Put the code in a local script. Then only that player will be able to see it. I can post in my answer.
You know a lot of things !! Thanks !! And one last question (sorry but it very difficult for me), how to make a part when the player touch the part, the beam became invisible and vice versa ?
Sorry, Could you explain in more detail? I'll help of course.
Yes, so I want to make, when a player touch a part, his beam became invisible and when he touch another part his beam became visible
Done. I'll edit it.