local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local Debris = game:GetService("Debris")
local player = Players.LocalPlayer
if not player then
error("LocalPlayer not found!")
return
end
local TOGGLE_KEY = Enum.KeyCode.E
local MAX_DISTANCE = 500
local MAX_PREVIEW_PARTS = 35
local WALL_TRANSPARENCY = 0.8
local TRACE_TIME = 0.12
local RAYCAST_COOLDOWN = 0.05
local enabled = false
local changedParts = {}
local lastScanAt = 0
local remote = ReplicatedStorage:FindFirstChild("WallbangWeaponEvent")
if remote then
remote:FireServer("SetWallbang", false)
end
local function isCharacterPart(part)
local model = part:FindFirstAncestorOfClass("Model")
return model and model:FindFirstChildOfClass("Humanoid") ~= nil
end
local function resetPart(part)
local old = changedParts[part]
if not old then
return
end
if part and part:IsA("BasePart") and part:IsDescendantOf(workspace) then
part.LocalTransparencyModifier = old.localTransparency
part.CanCollide = old.canCollide
end
changedParts[part] = nil
end
local function resetParts()
local partsToReset = {}
for part in pairs(changedParts) do
table.insert(partsToReset, part)
end
for _, part in ipairs(partsToReset) do
resetPart(part)
end
end
local function cleanupDeletedParts()
local partsToRemove = {}
for part in pairs(changedParts) do
if not part or not part:IsDescendantOf(workspace) then
table.insert(partsToRemove, part)
end
end
for _, part in ipairs(partsToRemove) do
changedParts[part] = nil
end
end
local function markPart(part)
if changedParts[part] or isCharacterPart(part) then
return
end
changedParts[part] = {
localTransparency = part.LocalTransparencyModifier,
canCollide = part.CanCollide,
}
part.LocalTransparencyModifier = WALL_TRANSPARENCY
part.CanCollide = false
end
local function makeParams(ignoreList)
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude
params.FilterDescendantsInstances = ignoreList
params.IgnoreWater = true
return params
end
local function scanPreview()
local camera = workspace.CurrentCamera
if not camera then
return
end
local ignoreList = {}
if player.Character then
table.insert(ignoreList, player.Character)
end
local origin = camera.CFrame.Position
local unit = camera.CFrame.LookVector
local remaining = MAX_DISTANCE
local activeParts = {}
for _ = 1, MAX_PREVIEW_PARTS do
local result = workspace:Raycast(origin, unit * remaining, makeParams(ignoreList))
if not result or not result.Instance then
break
end
local hit = result.Instance
table.insert(ignoreList, hit)
if hit:IsA("BasePart") then
if isCharacterPart(hit) then
break
end
markPart(hit)
activeParts[hit] = true
end
local traveled = (result.Position - origin).Magnitude
remaining -= traveled
if remaining <= 0 then
break
end
origin = result.Position + unit * 0.1
end
-- Безопасная итерация и сброс
local partsToReset = {}
for part in pairs(changedParts) do
if not activeParts[part] then
table.insert(partsToReset, part)
end
end
for _, part in ipairs(partsToReset) do
resetPart(part)
end
end
local function drawTrace(origin, endPosition)
local distance = (endPosition - origin).Magnitude
if distance <= 0 then
return
end
local part = Instance.new("Part")
part.Name = "LocalBulletTrace"
part.Anchored = true
part.CanCollide = false
part.CanQuery = false
part.Material = Enum.Material.Neon
part.Color = Color3.fromRGB(93, 184, 255)
part.Transparency = 0.15
part.Size = Vector3.new(0.045, 0.045, distance)
part.CFrame = CFrame.lookAt(origin, endPosition) * CFrame.new(0, 0, -distance / 2)
part.Parent = workspace
Debris:AddItem(part, TRACE_TIME)
end
local function fireTestShot()
local camera = workspace.CurrentCamera
if not camera then
return
end
local origin = camera.CFrame.Position
local direction = camera.CFrame.LookVector * MAX_DISTANCE
drawTrace(origin, origin + direction)
if remote then
remote:FireServer("Fire", origin, direction)
else
warn("[CombinedClient] WallbangWeaponEvent not found. Tracer is local-only.")
end
end
local function setEnabled(state)
enabled = state == true
if remote then
remote:FireServer("SetWallbang", enabled)
end
if not enabled then
resetParts()
end
print("Wallbang preview:", enabled)
end
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then
return
end
if input.KeyCode == TOGGLE_KEY then
setEnabled(not enabled)
return
end
if input.UserInputType == Enum.UserInputType.MouseButton1 then
fireTestShot()
end
end)
RunService.RenderStepped:Connect(function()
cleanupDeletedParts()
if not enabled then
resetParts()
return
end
local now = os.clock()
if now - lastScanAt >= RAYCAST_COOLDOWN then
scanPreview()
lastScanAt = now
end
end)
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local Debris = game:GetService("Debris")
local player = Players.LocalPlayer
if not player then
error("LocalPlayer not found!")
return
end
local TOGGLE_KEY = Enum.KeyCode.E
local MAX_DISTANCE = 500
local MAX_PREVIEW_PARTS = 35
local WALL_TRANSPARENCY = 0.8
local TRACE_TIME = 0.12
local RAYCAST_COOLDOWN = 0.05
local enabled = false
local changedParts = {}
local lastScanAt = 0
local remote = ReplicatedStorage:FindFirstChild("WallbangWeaponEvent")
if remote then
remote:FireServer("SetWallbang", false)
end
local function isCharacterPart(part)
local model = part:FindFirstAncestorOfClass("Model")
return model and model:FindFirstChildOfClass("Humanoid") ~= nil
end
local function resetPart(part)
local old = changedParts[part]
if not old then
return
end
end
local function resetParts()
local partsToReset = {}
for part in pairs(changedParts) do
table.insert(partsToReset, part)
end
end
local function cleanupDeletedParts()
local partsToRemove = {}
for part in pairs(changedParts) do
if not part or not part:IsDescendantOf(workspace) then
table.insert(partsToRemove, part)
end
end
end
local function markPart(part)
if changedParts[part] or isCharacterPart(part) then
return
end
end
local function makeParams(ignoreList)
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude
params.FilterDescendantsInstances = ignoreList
params.IgnoreWater = true
return params
end
local function scanPreview()
local camera = workspace.CurrentCamera
if not camera then
return
end
end
local function drawTrace(origin, endPosition)
local distance = (endPosition - origin).Magnitude
if distance <= 0 then
return
end
end
local function fireTestShot()
local camera = workspace.CurrentCamera
if not camera then
return
end
end
local function setEnabled(state)
enabled = state == true
end
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then
return
end
end)
RunService.RenderStepped:Connect(function()
cleanupDeletedParts()
end)