Hello, I have made a script so when a model of parts hit a wall that model that hits the wall is destroyed and then the model in the server storage is cloned. Although this works the only problem is that the 2nd time the model comes into contact with the wall it seems to not be destroyed and creates multiple duplicates. Here is the video and script for reference,
https://gyazo.com/07a419eb8e860a7e3a9eaafed1f93e1a
local part = script.Parent local wavemodel = game.Workspace.Wavemodel part.Touched:Connect(function(hit) wavemodel:Destroy() game.ServerStorage.Wavemodel:Clone().Parent = workspace end)
So it looks like you are trying to loop it.
You can Simply destroy the wave on hit with this function
part.Touched:Connect(function(hit) if hit then if hit.Name == "WaveModel" then hit:Destroy() end end end)
So that will destroy a wave if it hits the part. It wont spawn a new one. thats where the new function will come in handy. Because u didnt show the movement script for the wave, i can only do it like this.
function CreateNewWave() local wavemodel = game.ServerStorage:WaitForChild("Wavemodel") wavemodel:Clone().Parent = workspace end
This function will create a new Wave ( will spawn the model in workspace again.
So the complete script would look like this IMPORTANT: Place this in a normal script in ServerScriptService. not in the part.
local part = game.workspace. HERE THE PART NAME WHERE IT IS function CreateNewWave() local wavemodel = game.ServerStorage:WaitForChild("Wavemodel") wavemodel:Clone().Parent = workspace end local wavemodel = game.Workspace.Wavemodel part.Touched:Connect(function(hit) if hit then if hit.Name == "WaveModel" then hit:Destroy() CreateNewWave end end end)
This should fix it:
local part = script.Parent part.Touched:Connect(function(hit) if hit.Name == "WaveModel" then --Whenever something hits the part, it will see if the hit object is named "WaveModel" --Make sure the "WaveModel" is the same as the one in your ServerStorage hit:Destroy() --It destroys it if the object that hit the part name is "WaveModel" game.ServerStorage.WaveModel:Clone().Parent = workspace --Then clones it again end end)