Hi everyone, I’m a very new scripter and I’m trying to create a beam that is connected to a player’s HumanoidRootPart and a part in the workspace. I’m using a LocalScript as I want the beam to be client-sided but am running into issues with getting it to work. Any help would be appreciated, the code is below!
game.Players.OnPlayerAdded:Connect(function(player)
local Humanoid = player:FindFirstChild("Humanoid")
if Humanoid then
local Beam = game.ServerStorage.Beam
Beam:Clone()
Beam.Parent = player.HumanoidRootPart
Beam.Attachment0 = player.HumanoidRootPart.RootRigAttachment
Beam.Attachment1 = game.Workspace.Part.Attachment
end
end)```
PlayerAdded and PlayerRemoved events donot work on client what you can do is add your text outside events and it will be called when player joins
smt like this
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Beam = game.ReplicatedStorage.Beam
Beam:Clone()
Beam.Parent = Character.HumanoidRootPart
Beam.Attachment0 = Character.HumanoidRootPart.RootRigAttachment
Beam.Attachment1 = game.Workspace.Part.Attachment
i wrote this in the forum bc studio isnot opening it may have some errors
you also tried to access server storage which isnot possiple on client you can add the beam in replicated storage instead
and when u did Beam.Parent = Player it willnot work it should be the player`s character bc the Player isnot a 3d object
i recommend you to learn the differance between client and server as its very important
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local HumanoidRootPart = char:WaitForChild("HumanoidRootPart")
local RootAttachment = Instance.new("Attachment")
RootAttachment.Parent = HumanoidRootPart
local BeamPart = workspace:WaitForChild("Part") -- replace this with your workspace part
if not BeamPart:FindFirstChildOfClass("Attachment") then
local Attachment = Instance.new("Attachment") --Add new attachment if the part doesn't have
Attachment.Parent = BeamPart
end
local Beam = game.ReplicatedStorage.Beam
Beam.Attachment0 = RootAttachment
Beam.Attachment1 = BeamPart:WaitForChild("Attachment")
Beam.Parent = HumanoidRootPart
make sure you replace the BeamPart with the part you want in workspace
and add Beam to ReplicatedStorage