I wanted to make a gun somewhat like a lazer beam. Kind of like a neon ult if you played valorant. But there seems to be a problem with my scripts. I cant figure it out.
it doesn’t go out the fire hold and i can’t think of a way to add some kind of debris i think or something to delete the ray once it hits something.
it does this:
Local script
---{< Services >}---
local UIS: UserInputService = game:GetService("UserInputService")
local TS: TweenService = game:GetService("TweenService")
local StarterGui = game:WaitForChild("StarterGui")
local LocalPlayer = game.Players.LocalPlayer
---{< Events >}---
local Shot = script.Parent.Shoot
---{< Parts >}---
local Gun = script.Parent
local firePart = Gun.Firepart
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local PlayerGui = LocalPlayer.PlayerGui
local GUI = PlayerGui:WaitForChild("Energy")
local Cont = GUI:WaitForChild("Container")
local ChargeBar = Cont.Charge
---{< Modules >}---
local ray = require(Gun.Ray)
---{< Vars >}---
local Charge = 1000
Charge = math.clamp(Charge, 0, 1000)
local debounce = false
local shooting = false
---{< Main Code >}---
Gun.Activated:Connect(function()
shooting = true
while shooting and Charge > 0 do
--print("Shooting")
ChargeBar:TweenSize(UDim2.new(1, 0, Charge/1000, 0), "Out", "Linear", 0)
Shot:FireServer(mouse.Hit.Position)
ray(firePart.Position, mouse.Hit.Position)
--print(Charge)
Charge -= 5
task.wait(0.005)
if Charge <= 0 then
print("Energy ran out")
shooting = false
end
end
end)
Gun.Deactivated:Connect(function()
print("stopped firing")
shooting = false -- Reset shooting to false when deactivated
while Charge < 1000 and not shooting do
Charge += 2.5
task.wait(0.005)
ChargeBar:TweenSize(UDim2.new(1, 0, Charge/1000, 0), "Out", "Linear", 0)
--print(Charge)
end
end)
module script (for the vfx)
local defaultSettings = {
TextureSpeed = 5,
TextureLength = 5,
Texture = "rbxassetid://12781800668",
Color = ColorSequence.new(Color3.fromRGB(251, 255, 0)),
Width0 = 1,
Width1 = 1,
Transparency = NumberSequence.new(0),
LightEmission = 1,
FaceCamera = true,
}
return function (Source, Point, Settings)
local direction = (Point - Source).Unit
--local distance = (Point - Source).Magnitue
--properties
local CBullet = Instance.new("Part")
CBullet.Anchored = true
CBullet.CanCollide = false
CBullet.Size = Vector3.new(0.05, 0.05, 0.05)
CBullet.Transparency = 1
CBullet.Parent = workspace
CBullet.CFrame = CFrame.lookAt(Source, Source + direction)
-- Attachments
local AT0 = Instance.new("Attachment")
AT0.Position = Source
AT0.Parent = CBullet
local AT1 = Instance.new("Attachment")
AT1.Position = Point
AT1.Parent = CBullet
-- Beam Settings
local beam = Instance.new("Beam")
for property, value in pairs(defaultSettings) do
beam[property] = value
end
if Settings then
for property, value in pairs(Settings) do
beam[property] = value
end
end
beam.Attachment0 = AT0
beam.Attachment1 = AT1
beam.Parent = workspace
print("Firing Beam from", Source, "to", Point)
end
i dont think the server script will be relevant to this problem so i wont post it.
thanks for the help.