Hello, So what I am trying to do is if the clone part touches something the thing it touched gets destroyed I have tried many ways to do this but I cant figure out how.
Here is my script.
local testplayer = game.Workspace.TestPlayer
local userInputService = game:GetService(“UserInputService”)
local tweenService = game:GetService(“TweenService”)
So you want the cloned part to destroy anything it touches, right?
Well from what I can see on your script, you haven’t added anything that could check if the part has been touched. Also, you are deleting the cloned part.
local testplayer = game.Workspace.TestPlayer
local userInputService = game:GetService(“UserInputService”)
local tweenService = game:GetService(“TweenService”)
.Touched does not work because it requires objects to physically touch. Tweening on the other hand interpolates values and does not move them physically.
So instead, we can utilize a Region3 loop.
local UIS = game:GetService("UserInputService")
local TWS = game:GetService("TweenService")
local testPlayer = workspace:FindFirstChild("TestPlayer")
UIS.InputBegan:Connect(function(input, processed)
if processed then
return
end
if input.KeyCode == Enum.KeyCode.Space then
local clone = Instance.new("Part")
clone.Parent = workspace
clone.Name = "Laser"
clone.CastShadow = false
clone.Anchored = true
clone.Material = "Neon"
clone.BrickColor = BrickColor.new("Really red")
clone.Size = Vector3.new(1, 1, 4)
clone.CFrame = testPlayer.PrimaryPart.CFrame
TWS:Create(clone, TweenInfo.new(2, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, -1, false, 0), {Position = workspace.Target.Position}):Play()
clone:GetPropertyChangedSignal("Position"):Connect(function()
local params = OverlapParams.new()
params.FilterDescendantsInstances = {testPlayer, clone} -- BLACKLIST FOR OBJECTS THAT CAN'T BE DESTROYED
params.FilterType = Enum.RaycastFilterType.Blacklist
local arr: {BasePart} = workspace:GetPartBoundsInBox(clone.CFrame, clone.Size, params)
for _,v: BasePart in ipairs(arr) do
v:Destroy()
end
end)
end
end)