Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

how to connect a beam from a players character to a object?

Basically im trying to make a tutorial for my game ive got some of it covered but im trying to make arrows pointing to a npc named "Master Baker" and im trying to get a script to place one end of the beam into the character and the other to the npc and here is the script ive got:

local EVENT = game.ReplicatedStorage.Tutorial
EVENT.OnServerEvent:Connect(function()
	game.Players.PlayerAdded:Connect(function(plr)
		plr.CharacterAdded:Connected(function(char)
			local ATT1 = game.ReplicatedStorage:WaitForChild("TUTP") --a model which contains attachment0
			ATT1.Parent = plr.char:WaitForChild('LowerTorso') -- im trying to place the model into the torso
			ATT1.CFrame = char:WaitForChild('LowerTorso').CFrame
	 
	        	local Weld = Instance.new('ManualWeld')
	        	Weld.Part0 = ATT1     
	        	Weld.Part1 = char:WaitForChild('LowerTorso')
	        	Weld.C0 = ATT1.CFrame:inverse() * char:WaitForChild('LowerTorso').CFrame
	        	Weld.Parent = char:WaitForChild('LowerTorso')
			
			local beam = game.ReplicatedStorage.Beam:Clone()
			beam.Parent = plr.char:WaitForChild('LowerTorso')
			beam.Attachment1 = ATT1.Attachment0
		end)
	end)
end)

after all this i got nothing, not even a warning or error so is there a way this can be fixed or am i missing a step which i forgot like giving a position to where the beam has to be placed?

(also wanted to point out that i attachment1 is placed in the torso of the npc Master Baker.)

2 comments

0

A beam is connected to attachments. If you want your beam to be visible you need to place an attachment in both players, then set the attachments in the beams property.

0

i posted a new script that ive worked up but it still doesnt work so if anyone can tweak this and fix it that would be awsome!

1 answer

local attachment = Instance.new("Attachment")

Beams are only visible if it has a start point (attachment0), and an end point (attachment1). If you're wanting to add a beam to anything mid-way through a game, you'll need to create attachments,

local attachment0 = Instance.new("Attachment")
attachment0.Parent = --Start part

local attachment1 = Instance.new("Attachment")
attachment1.Parent = --End part

local beam = Instance.new("Beam")
beam.Parent = --It's best to make the beam's parent the same as the attachment0's parent, just to keep things organized.
beam.Attachment0 = attachment0
beam.Attachment1 = attachment1

This would create a basic, default beam, if you wish to use a special beam, change the line;

local beam = Instance.new("Beam")

to something like;

local beam = game.ReplicatedStorage.Beam:Clone()

Hope this helps!

2 comments

0

:)

0

hey im using te script youve given and ive parented attackment0 into char which is the character and i parented attachment1 into game.workspace.[Master Baker] and when i start the game nothing happens?

This discussion is preserved as it was. New answers, comments, and votes are closed.