Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Make a Player-Part Beam ?

Asked by
mist0s 38
4 years ago
Edited 4 years ago

Hi, I want to make a Player-Part Beam, its for indicate the way. But it doesn't work. Here is the code:

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)

local start = Instance.new("Attachment")
start.Name = "start"
start.Parent = player.character:FindFirstChild("LowerTorso")


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 = "Really Red"
Beam.Width0 = 3
Beam.Width1 = 3
end)

Thanks for answer :D

1 answer

Log in to vote
0
Answered by
noammao 294 Moderation Voter
4 years ago
Edited 4 years ago
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) -- "player" is the part that touched the part.
    local Humanoid = player.Parent:FindFirstChild("Humanoid") -- Declaring that the object contains a part called Humanoid.
    if Humanoid then -- Check if it contains a humanoid. And if true, do.
    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.

0
Dude, it work, really THANKS ! mist0s 38 — 4y
0
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! noammao 294 — 4y
0
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 ? mist0s 38 — 4y
0
Put the code in a local script. Then only that player will be able to see it. I can post in my answer. noammao 294 — 4y
View all comments (4 more)
0
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 ? mist0s 38 — 4y
0
Sorry, Could you explain in more detail? I'll help of course. noammao 294 — 4y
0
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 mist0s 38 — 4y
0
Done. I'll edit it. noammao 294 — 4y
Ad

Answer this question