What I need
1.) How do I get the C4 to forwards wherever I place it?
2.) If you know any sort of optimization for the code PLEASE tell me, the code I wrote is just a mess and I need help.
Video of my current system
Code
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local C4 = ReplicatedStorage:WaitForChild("C4")
local player = Players.LocalPlayer
local Tool = script.Parent
local Mouse = player:GetMouse()
local equipped = false
Tool.Equipped:Connect(function()
preC4 = C4:Clone()
preC4.Parent = workspace
for i, v in pairs(preC4:GetDescendants()) do
if v:IsA("MeshPart") then
v.Color = Color3.fromRGB(0, 255, 0)
v.Transparency = 0.5
elseif v:IsA("UnionOperation") then
v.Color = Color3.fromRGB(0, 255, 0)
v.UsePartColor = true
end
end
preC4:MoveTo(Mouse.Hit.Position)
equipped = true
end)
Tool.Unequipped:Connect(function()
preC4:Destroy()
equipped = false
end)
Tool.Activated:Connect(function()
local c4 = C4:Clone()
Mouse.TargetFilter = preC4
local weldNew = Instance.new("WeldConstraint", c4)
local p1 = Mouse.Target
c4.Parent = workspace
c4:MoveTo(Mouse.Hit.Position)
weldNew.Part1 = c4.Handle
weldNew.Part0 = p1
c4.Handle.Anchored = false
weldNew.Enabled = true
preC4:Destroy()
script.Parent:Destroy()
end)
Mouse.Move:Connect(function()
if equipped then
Mouse.TargetFilter = preC4
preC4:MoveTo(Mouse.Hit.Position)
end
end)