I am currently trying to delete an object on the client side. When I delete it with :Destroy(), it freezes in place. When I try to put it in a different service, the same thing happens. Here is my script:
local Player = script.Parent.Parent
local Character = Player.CharacterAdded:Wait()
local Root = Character:WaitForChild("HumanoidRootPart")
local value = game.Workspace.Cosmic
local Cvalue = value.Value
local positionHistory = {}
local delayTime = 1 -- in seconds
local updateInterval = 0.01 -- lower = smoother
local maxHistoryLength = math.ceil(delayTime / updateInterval)
value:GetPropertyChangedSignal("Value"):Connect(function()
Cvalue = value.Value
local clone = game.ReplicatedStorage.Rig:Clone()
clone.Parent = workspace
if Cvalue == true then
while Cvalue do
table.insert(positionHistory, Root.CFrame)
if #positionHistory > maxHistoryLength then
clone.HumanoidRootPart.CFrame = positionHistory[1]
table.remove(positionHistory, 1)
end
task.wait(updateInterval)
end
else
clone.Parent = game.ReplicatedStorage
clone:Destroy()
end
end)
Here is the script for the part intended to delete the clone:
script.Parent.Transparency = 1
local value = game.Workspace.Cosmic
local End = script.Parent
End.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
value.Value = false
end
end)
Lastly, here is a video of what happens.
I want it so that the rig disappears when I touch the transparent red block rather than just stop.
local Player = script.Parent.Parent
local Character = Player.CharacterAdded:Wait()
local Root = Character:WaitForChild("HumanoidRootPart")
local value = game.Workspace.Cosmic
local Cvalue = value.Value
local positionHistory = {}
local delayTime = 1 -- in seconds
local updateInterval = 0.01 -- lower = smoother
local maxHistoryLength = math.ceil(delayTime / updateInterval)
value:GetPropertyChangedSignal("Value"):Connect(function()
Cvalue = value.Value
local clone = game.ReplicatedStorage.Rig:Clone()
clone.Parent = workspace
if Cvalue == true then
while value.Value do
table.insert(positionHistory, Root.CFrame)
if #positionHistory > maxHistoryLength then
clone.HumanoidRootPart.CFrame = positionHistory[1]
table.remove(positionHistory, 1)
end
task.wait(updateInterval)
end
clone:Destroy()
else
clone:Destroy()
end
end)