Destroy tool HELP

So, I wanted to make a destroy tool that destroys everything but that destroy tool also destroys player parts…
Here is the script:

Local Script:

local maxDistance = 15
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local ReplicatedStorage = game:GetService("ReplicatedStorage")

script.Parent.Activated:Connect(function()
	if Mouse.Target.Parent == "Humanoid" then
		
	else
		if Mouse.Target.Locked == false then
			local Target = Mouse.Target
			ReplicatedStorage.DestroyEvent:FireServer(Target)
		end
	end
end)

game.ReplicatedStorage.DestroyEvent:FireServer()

Script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")

local goal = {}
goal.Transparency = 1

local tweenInfo = TweenInfo.new(0.75)


ReplicatedStorage.DestroyEvent.OnServerEvent:Connect(function(player, Target)
	local tween = TweenService:Create(Target, tweenInfo, goal)
	Target.CanCollide = false
	tween:Play()
end)

Also I would like to add a destroy distance. Thank you!

Try if Mouse.Target.Parent:FindFirstChildWhichIsA("Humanoid") then

2 Likes

So adding on to this, if the mouse.Target is an accessory, it will delete the accessory.
To prevent this, you can do this:

if Mouse.Target.Parent:FindFirstChildWhichIsA("Humanoid") or Mouse.Target.Parent.Parent:FindFirstChildWhichIsA("Humanoid") then

end

Also, in order to protect against exploiting, follow along: you should put the code that detects if it is a Humanoid on the Server Script and not on the local script. Also put the if Mouse.Target.Locked == false then inside of the server script. I would also recommend double checking the mouse.Target using raycasting on the server side to make sure that the player can’t exploit this. This is because exploiters can easily manipulate mouse.Target into something else when you fire the remote event.

Also I recommend learning raycasting because raycasting is much, much, better than mouse.Target

Also, something else, since accessories can hinder raycasting and mouse.Target, you should set a script that sets the CanQuery property of the accessory parts to false.
This makes it so the accessories shouldn’t block rays or mouse.Target.

1 Like

Thank you for both of the answer but it looks like I can’t give to two people the Solution

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.