-
What do you want to achieve? I have a wooden board in my game that I want destroy-able by the player with a crowbar. The crowbar inside the game is comparable to the classic LinkedSword.
-
What is the issue? I’m not sure how to accomplish this.
-
What solutions have you tried so far? I have not found anything that pertains to my issue.
To do something like this, you need to make a touched event. Then it can detect whether it was touched by the crowbar or not. You can do so by checking like:
if blah:IsA("Tool") and blah.Name == "Crowbar" then
If it was touched by the crow bar, you make it destroyable like you want. You can do this part by like inserting an explosion to the brick and then destroying it, or destroy and clone it like 10 times whilst reducing the size to 1/10 then making them disappear, etc…
Using what @Bottrader said, you can then proceed to have the part destroyed, unanchored, sent to debris, etc.
You could continue on and use script.Parent:Destroy() or script.Parent.Anchored = false
.
How could I create a touched event to unanchor when touched?
So, in the Brick you could have a script with the following:
script.Parent.Touched:Connect(function(Part) --Fires everytime the part is touched by something
if Part.Name == "Crowbar" and Part:IsA("Tool") --checking to make sure it is the crowbar that touched it
script.Parent.Anchored = false -- sets to unachored
end
end)
Since tools have a Handle, you can use the following code to unanchor a part, as you said.
local tool = script.Parent
local handle = tool:WaitForChild("Handle")
local canHit = true
handle.Touched:Connect(function(touchedPart) --.Touched returns the part that touched it.
if touchedPart.Name == "WoodenBoard" and canHit then --You can replace "WoodenBoard" with whatever the actual name is
canHit = false
touchedPart.Anchored = false --Unanchors the part
wait(1)
canHit = true --Waits a second before you can hit the board again
end
end)
P.S. you’ll want to put this code in a script that’s inside the crowbar
Would that cause a lag spike shouldn’t you add a debounce?
Thanks for the advice! Will use in the future!