Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Services
- local Players = game:GetService("Players")
- local RunService = game:GetService("RunService")
- local Workspace = game:GetService("Workspace")
- -- Local player reference
- local LocalPlayer = Players.LocalPlayer
- -- Table to store beams
- local Beams = {}
- -- Function to create a beam for a player
- local function createBeam(player)
- if player == LocalPlayer then return end
- local function onCharacterAdded(character)
- local head = character:WaitForChild("Head", 5)
- local bodyEffects = character:WaitForChild("BodyEffects", 5)
- local mousePos = bodyEffects and bodyEffects:FindFirstChild("MousePos")
- if head and mousePos then
- -- Create attachments
- local att0 = Instance.new("Attachment", head)
- local att1 = Instance.new("Attachment", Workspace.Terrain)
- -- Create beam
- local beam = Instance.new("Beam")
- beam.Attachment0 = att0
- beam.Attachment1 = att1
- beam.FaceCamera = true
- beam.Width0 = 0.2
- beam.Width1 = 0.2
- beam.Color = ColorSequence.new(Color3.fromRGB(255, 58, 61))
- beam.Transparency = NumberSequence.new(1) -- Initially invisible
- beam.Parent = att0
- -- Store in Beams table
- Beams[player] = {Beam = beam, Att1 = att1, MousePos = mousePos, Character = character}
- end
- end
- -- Connect to CharacterAdded event
- player.CharacterAdded:Connect(onCharacterAdded)
- -- If character already exists, create beam
- if player.Character then
- onCharacterAdded(player.Character)
- end
- end
- -- Create beams for existing players
- for _, player in ipairs(Players:GetPlayers()) do
- createBeam(player)
- end
- -- Create beams for new players
- Players.PlayerAdded:Connect(function(player)
- createBeam(player)
- end)
- -- Update beams every frame
- RunService.RenderStepped:Connect(function()
- for player, data in pairs(Beams) do
- local character = data.Character
- if character and character.Parent then
- local hasTool = false
- for _, tool in ipairs(player.Backpack:GetChildren()) do
- if tool:IsA("Tool") then
- hasTool = true
- break
- end
- end
- for _, tool in ipairs(character:GetChildren()) do
- if tool:IsA("Tool") then
- hasTool = true
- break
- end
- end
- if hasTool and data.MousePos then
- data.Att1.Position = data.MousePos.Value
- data.Beam.Transparency = NumberSequence.new(0) -- Visible
- else
- data.Beam.Transparency = NumberSequence.new(1) -- Invisible
- end
- else
- -- Cleanup if character is not valid
- if data.Beam then data.Beam:Destroy() end
- if data.Att1 then data.Att1:Destroy() end
- Beams[player] = nil
- end
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement