#Digging

1 messages · Page 1 of 1 (latest)

old bone
#

i need help making a script so when I hold a tool called Shovel and click a part it will play an audio and delete the part, ive been trying to do this for an hour and it seems so simple but it simply wont work I need help.

last valve
#

what scripts have you tried for the tool?

#

@old bone ?

old bone
last valve
old bone
last valve
#

i can try

#

uhm

#

hold on im making the script

#

s

old bone
#

Ok

last valve
#

here is localscript

--local script
local remoteevent = script.Parent.RemoteEvent --replace this with a remote event related to the tool

script.Parent.Activated:Connect(function()
    local mouse = game.Players.LocalPlayer:GetMouse()
    local targetpart = mouse.Target
    
    if targetpart and targetpart.Locked == false then
        remoteevent:FireServer(targetpart)
    end
end)```
and here is server script
```lua
--server script
local sound = script.Parent.Handle.Sound --replace this so it references the sound that you're trying to play

script.Parent.RemoteEvent.OnServerEvent:Connect(function(player, targetpart)
    if targetpart ~= nil then
        sound:Play()
        targetpart:Destroy()
    end
end)```
peak belfryBOT
#

studio** You are now Level 1! **studio

old bone
#

where do I put these

last valve
#

in the tool

#

btw you might need to add a remote event related to the tool

old bone
#

ok how do i do thst

last valve
#

do you know how to add objects like tools and scripts?

#

do the same thing but with a "RemoteEvent"

old bone
#

i have 0 scripting knowledge

peak belfryBOT
#

studio** You are now Level 3! **studio

last valve
#

the explorer tree might have to look like this (pretend the blue script is a localscript)

#

in the tool

#

also this only works for unlocked parts so it doesnt work for the baseplate and for some reason players

old bone
#

its only supposed to remove a certain part I dont want it destroying everything

last valve
#

i can make it so it only removes parts with a certain name

#

or if the parts contain a certain name

old bone
last valve
#

it only takes modifying the local script

#
--local script
local remoteevent = script.Parent.RemoteEvent --replace this with a remote event related to the tool
local name = "DigPart" --put the name you want the script to only destroy parts with

script.Parent.Activated:Connect(function()
    local mouse = game.Players.LocalPlayer:GetMouse()
    local targetpart = mouse.Target
    
    if targetpart and targetpart.Locked == false and string.match(targetpart.Name, name) then
        remoteevent:FireServer(targetpart)
    end
end)```
last valve
#

yeah like that

old bone
#

ok let me test

last valve
#

btw on the first post i think you forgot about this rule in the guidelines

#

oh wait

#

i read it wrong

old bone
#

i didnt post code

last valve
#

yeah i read it wrong

old bone
#

wow that acutally worked

#

thanks slike

#

is there a way to add like a 1 second cooldown

#

so its not spammed

last valve
#

yes but i have to bed

old bone
#

Ok

#

can u just tell me where to add it

#

local or server

last valve
#

can be either

old bone
#

Ok

#

which is better

warm flame
#

server is better to prevent exploiters from making no cooldown