How to make a beam draw from a part to a player

I used Roblox’s beam creation through a script and then just changed the values to HumanoidRootPart and a Part as the draw area but I cannot see the line. I doesn’t really matter where it goes but connecting the player with a beam to a part.

Its in a script.

local att0 = Instance.new(“Attachment”)
local att1 = Instance.new(“Attachment”)

local plr = game.Players:GetPlayers()
local character = plr.Character
local HumanoidRootPart = character and character:FindFirstChild(“HumanoidRootPart”)

att0.Parent = game.Workspace.Part
att1.Parent = HumanoidRootPart

local beam = Instance.new(“Beam”)
beam.Attachment0 = att0
beam.Attachment1 = att1

– appearance properties
beam.Color = ColorSequence.new({ – a color sequence shifting from white to blue
ColorSequenceKeypoint.new(0, Color3.fromRGB(255, 255, 255)),
ColorSequenceKeypoint.new(1, Color3.fromRGB(0, 255, 255)),
})
beam.LightEmission = 1 – use additive blending
beam.LightInfluence = 0 – beam not influenced by light
beam.Texture = “rbxasset://textures/particles/sparkles_main.dds” – a built in sparkle texture
beam.TextureMode = Enum.TextureMode.Wrap – wrap so length can be set by TextureLength
beam.TextureLength = 1 – repeating texture is 1 stud long
beam.TextureSpeed = 1 – slow texture speed
beam.Transparency = NumberSequence.new({ – beam fades out at the end
NumberSequenceKeypoint.new(0, 0),
NumberSequenceKeypoint.new(0.8, 0),
NumberSequenceKeypoint.new(1, 1),
})
beam.ZOffset = 0 – render at the position of the beam without offset

– shape properties
beam.CurveSize0 = 0 – create a curved beam
beam.CurveSize1 = 0 – create a curved beam
beam.FaceCamera = true – beam is visible from every angle
beam.Segments = 10 – default curve resolution
beam.Width0 = 1 – starts small
beam.Width1 = 1 – ends big

– parent beam
beam.Enabled = true
beam.Parent = att0

1 Like

did you get any errors?

what did the output show

1 Like

Here’s the problem:

GetPlayers() returns a table of players. you have to specify a player in the table, even if there’s only 1 player. The table itself doesn’t have any properties.
The fix (for serverside):

wait(2) --allow for the player instance to load
local plr = game.Players:GetPlayers()[1]
local character = plr.Character

Or if it’s a local script:

local plr = game.Players.LocalPlayer
local character = plr.Character
1 Like