What do I want to achieve? I made a functional planks when touched, it will unanchored and reset the positions back.
But the issues is that when it reset many times, part became like conveyor that pushes. How I can reset that?
My video:
https://gyazo.com/5366379beff132884b5d4fcde1cd8476
My script:
local folder = script.Parent
local function StoreInitialPositions(model)
local asset = model:FindFirstChild("Asset")
local positions = {}
for _, part in pairs(asset:GetChildren()) do
if part:IsA("BasePart") then
positions[part] = part.CFrame
end
end
return positions
end
local function ResetToInitialPositions(model, initialPositions)
for part, position in pairs(initialPositions) do
part.Anchored = true
part.CFrame = position
end
end
local function EnableTouch(model)
local asset = model:FindFirstChild("Asset")
local initialPositions = StoreInitialPositions(model)
local touch = model:FindFirstChild("TouchPart")
local debounce = false
touch.Touched:Connect(function(hit)
if debounce == false and hit.Parent:FindFirstChild("Humanoid") then
debounce = true
local randomTime = math.random(2, 10) / 10
task.wait(randomTime)
print(randomTime)
for _, part in pairs(asset:GetChildren()) do
if part:IsA("BasePart") then
part.Anchored = false
end
end
task.wait(3)
ResetToInitialPositions(model, initialPositions)
debounce = false
end
end)
end
for _, model in pairs(folder:GetChildren()) do
if model:IsA("Model") then
EnableTouch(model)
end
end