Hey i have these scripts they work like i want but theres a glitch where the beam works only one time if i try the second time to use the beam it doesnt work anyone knows whats the problem and no theres nothing in the output except the 05:44:32.596 Missing one or more beams! (x2) - Server - Script:45
Server script
local tool = script.Parent
local remoteEvent = tool:WaitForChild("RemoteEvent")
local activeBeams = {}
local function cleanupBeams(player)
if activeBeams[player] then
for _, obj in pairs(activeBeams[player]) do
if obj then
obj:Destroy()
end
end
activeBeams[player] = nil
end
end
local function onRemoteEventFired(player, action, target)
local character = player.Character
if not character then
warn("Character is invalid!")
return
end
local head = character:FindFirstChild("Head")
if not head then
warn("Head is missing!")
return
end
local laserStart1 = head:FindFirstChild("LaserStart")
local laserStart2 = head:FindFirstChild("LaserStart2")
if not laserStart1 or not laserStart2 then
warn("Attachments LaserStart or LaserStart2 missing!")
return
end
local beam1 = tool:FindFirstChild("Beam1")
local beam2 = tool:FindFirstChild("Beam2")
local beam3 = tool:FindFirstChild("Beam3")
local beam4 = tool:FindFirstChild("Beam4")
if not (beam1 and beam2 and beam3 and beam4) then
warn("Missing one or more beams!")
return
end
if action == "Start" then
cleanupBeams(player)
if not target or not target:FindFirstChild("Humanoid") then
warn("Target is not a valid character!")
return
end
local targetPart = target:FindFirstChild("Head") or target:FindFirstChild("Torso")
if not targetPart then
warn("Target has no suitable part for attachment!")
return
end
local targetAttachment1 = Instance.new("Attachment")
targetAttachment1.Parent = targetPart
local targetAttachment2 = Instance.new("Attachment")
targetAttachment2.Parent = targetPart
beam1.Attachment0 = laserStart1
beam1.Attachment1 = targetAttachment1
beam1.Color = ColorSequence.new(Color3.fromRGB(255, 0, 0))
beam1.Width0 = 0.2
beam1.Width1 = 0.2
beam1.FaceCamera = true
beam1.Parent = head
beam2.Attachment0 = laserStart2
beam2.Attachment1 = targetAttachment2
beam2.Color = ColorSequence.new(Color3.fromRGB(0, 255, 0))
beam2.Width0 = 0.2
beam2.Width1 = 0.2
beam2.FaceCamera = true
beam2.Parent = head
beam3.Attachment0 = laserStart1
beam3.Attachment1 = targetAttachment1
beam3.Color = ColorSequence.new(Color3.fromRGB(0, 0, 255))
beam3.Width0 = 0.2
beam3.Width1 = 0.2
beam3.FaceCamera = true
beam3.Parent = head
beam4.Attachment0 = laserStart2
beam4.Attachment1 = targetAttachment2
beam4.Color = ColorSequence.new(Color3.fromRGB(255, 255, 0))
beam4.Width0 = 0.2
beam4.Width1 = 0.2
beam4.FaceCamera = true
beam4.Parent = head
activeBeams[player] = {
beam1 = beam1,
beam2 = beam2,
beam3 = beam3,
beam4 = beam4,
targetAttachment1 = targetAttachment1,
targetAttachment2 = targetAttachment2,
}
task.delay(5, function()
cleanupBeams(player)
end)
elseif action == "Stop" then
cleanupBeams(player)
end
end
remoteEvent.OnServerEvent:Connect(onRemoteEventFired)
Local script
local tool = script.Parent
local remoteEvent = tool:WaitForChild("RemoteEvent")
local player = game.Players.LocalPlayer
local isHolding = false
local holdStartTime = 0
local function onKeyPress(input, gameProcessed)
if input.KeyCode == Enum.KeyCode.Q and not gameProcessed then
if not isHolding then
isHolding = true
holdStartTime = tick()
local mouse = player:GetMouse()
if mouse and mouse.Target then
local target = mouse.Target.Parent
if target:FindFirstChild("Humanoid") then
local targetPosition = mouse.Target.Position
remoteEvent:FireServer("Start", target)
else
isHolding = false
end
else
isHolding = false
end
end
end
end
local function onKeyRelease(input)
if input.KeyCode == Enum.KeyCode.Q and isHolding then
isHolding = false
remoteEvent:FireServer("Stop")
end
end
game:GetService("RunService").RenderStepped:Connect(function()
if isHolding and tick() - holdStartTime > 5 then
isHolding = false
remoteEvent:FireServer("Stop")
end
end)
game:GetService("UserInputService").InputBegan:Connect(onKeyPress)
game:GetService("UserInputService").InputEnded:Connect(onKeyRelease)