My code doesn't work for some reason?

I’m trying to make a beam between a player and a part it doesn’t work even without the warn please help me here’s the code:

--[[local repstorage = game:GetService("ReplicatedStorage")
local player = game:GetService("Players").LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
repstorage.CreateBeam.OnClientEvent:Connect(function(player, deliverypoint)
	local attachment1 = Instance.new("Attachment", char.HumanoidRootPart)
	local attachment2 = Instance.new("Attachment", workspace:FindFirstChild(deliverypoint.Name))
	local beam = Instance.new("Beam", char.HumanoidRootPart)
	beam.Attachment0 = attachment1
	beam.Attachment1 = attachment2
end)]]
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local player = Players.LocalPlayer

local function onBeamCreated(deliverypoint)
	local character = player.Character or player.CharacterAdded:Wait()
	local rootPart = character:WaitForChild("HumanoidRootPart")

	local targetPart = workspace:FindFirstChild(deliverypoint)
	if targetPart == nil or not targetPart:IsA("BasePart") then
		warn("Invalid deliverypoint: ", deliverypoint)
		return
	end

	local attachment1 = Instance.new("Attachment", rootPart)
	local attachment2 = Instance.new("Attachment", targetPart)

	local beam = Instance.new("Beam", rootPart)
	beam.Attachment0 = attachment1
	beam.Attachment1 = attachment2
end

ReplicatedStorage.CreateBeam.OnClientEvent:Connect(onBeamCreated)

A proximity prompt fires the client and I know it is running. The commented out code is my past code I don’t wanna delete.

2 Likes

Is the deliverypoint a string? Because :FindFirstChild() doesn’t support instances.

deliverypoint was sent as DeliveryPoint.Name.

Is the beam appearing in the explorer?

nope its not appearing in the explorer

Put print after this line and check if it’s actually printing:

beam.Attachment1 = attachment2

alright i checked and it is printing

Try premaking the beam, and then just cloning it and setting all the properties you need.

that didnt work either i put it in repstorage and cloned it into workspace

And it doesn’t even appear in the explorer once again?

Write --!strict in the start of the script and see if it
gives any errors that might be the problem.

Tratium, yes, probacon; I tried that and got nothing. Is it just

--!strict

as a comment?

That’s really weird, I tried your script and it works perfectly fine:
image

Are you 100% sure that the script is running? Try printing out values between lines.

Maybe the parts in my game aren’t loading? Studio isn’t working currently but I’ll try that.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.