I’m working on a game and I’m trying to get an axe to cut vines. but I’m not an experienced scripter. The script I’m trying to figure out is, how to delete and object with a certain tool. Since I’m not good at coding I’m gonna need some help!
There are definitely a bunch of ways to do this. Here’s a really simplified version of what you are looking for! Here I have a tool set up to cut down vines any time the “Blade” touches a part who’s parent is named “Vines” thus deleting the model.
--"Cut" script
local tool = script.Parent
tool.Blade.Touched:Connect(function(hit)
if hit.Parent and hit.Parent.Name == "Vines" then
hit.Parent:Destroy()
end
end)
ok so first you will need to make the tool itself then inside put a Script, LocalScript, and a RemoteEvent.
Local Script:
local player = game.Players.LocalPlayer
local RE = script.Parent:WaitForChild("RemoteEvent")
local mouse = player:GetMouse()
local tool = script.Parent
tool.Equipped:Connect(function(mouse)
mouse.Button1Down:Connect(function()
if mouse.Target and mouse.Target.Parent then
RE:FireServer(mouse.Target)
end
end)
end)
Script:
script.Parent.RemoteEvent.OnServerEvent:Connect(function(player, part)
part:Destroy()
end)
The local script will get the what the players mouse is on then send it to the server with the remote event. which gets picked up by the server script and destroys the part if its name is “Vine”.
Wow! Thanks! Ill check out the other ones! thanks for the help Barothoth!
When I put everything into place. my tool started deleting everything I clicked? I think something happened! but ill try to check it!
here is an updated local script that will only destroy a part if it is named “Vine”
local player = game.Players.LocalPlayer
local RE = script.Parent:WaitForChild("RemoteEvent")
local mouse = player:GetMouse()
local tool = script.Parent
tool.Equipped:Connect(function(mouse)
mouse.Button1Down:Connect(function()
if mouse.Target and mouse.Target.Parent then
print(mouse.Target)
if mouse.Target.Name == "Vine" then
RE:FireServer(mouse.Target)
end
end
end)
end)
It’s fixed! Thank you for helping Porkloinial! The issue was solved and it cuts them 1 by 1!
Wouldn’t that server script be extremely easy to exploit? Exploiters could just input anything in the workspace as the parameter and it’ll get deleted.
You could add a check on the server before it gets deleted. to make sure it is named “Vine”.