I’ve created a simple test script for a star-wars inspired laser gun I’ll be making soon, and what I’ve got at the moment works fine, but what I’d like to happen is the laser part is destroyed upon touching any part. I can easily do the logic to make a character take damage and stuff but I can’t figure out how to make the Touched event fire in the first place. Here is the code I have right now, feel free to comment on any improvements I can make if you notice any anyway:
local TweenService = game:GetService("TweenService")
local ray = workspace.Ray
local target = workspace.Target
local origin = workspace.Origin
local goal = {}
goal.Position = target.Position
local distance = (origin.Position - target.Position).magnitude
local tweenInfo = TweenInfo.new(
0.5*distance/100,
Enum.EasingStyle.Linear,
Enum.EasingDirection.Out,
0,
false,
0
)
ray.CFrame = CFrame.new(origin.CFrame.Position, target.CFrame.Position) * CFrame.Angles(0,
math.rad(90), 0)
local tween = TweenService:Create(ray, tweenInfo, goal)
wait(2)
tween:Play()
Thanks.