Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Having problems with cloning on the 2nd time of contact between a model and part?

Asked by 5 years ago

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)

2 answers

Log in to vote
0
Answered by 5 years ago

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)

0
Same, I didn't know what movement script he was using, but i'm guessing that he used "BodyVelocity" as the part was moving and was still floating. XviperIink 428 — 5y
0
Yeah I used body velocity and body force. iChaboyy 7 — 5y
0
Did it work? :) If you have any more questions, just ask Paintertable 171 — 5y
0
Doesn't seem to work after setting the correct variables and fixing a few things, it seems to just hit the wall now isn't being destroyed. (This is before the model is cloned) iChaboyy 7 — 5y
View all comments (11 more)
0
Do you mind adding me on discord so communication can be quicker and efficient? Chickensalt#0386 iChaboyy 7 — 5y
0
yes, we can do that. Paintertable 171 — 5y
0
Currently im in school, i could talk to you in like 6-7 houres? Paintertable 171 — 5y
0
Sure sounds like a plan I have plenty of time to get thidone so I’ll see you then, send a fr on disc and I’ll accept. iChaboyy 7 — 5y
1
Well, i tested mine it work for ever lmao...? XviperIink 428 — 5y
0
Mine should normaly work too, He probably has a mistake somewhere else. Well, he could atleast try your Code idk Paintertable 171 — 5y
0
Both don’t seem to work at all now, the model is just hitting the wall and nothing is happening, gonna have a look at it when I get home iChaboyy 7 — 5y
0
I’ve found the problem, can you contact me on discord to help me solve it? iChaboyy 7 — 5y
0
what is the problem? XviperIink 428 — 5y
0
I tested mine it works forever until i stopped it. Probably you had made a mistake somewhere when changing it? XviperIink 428 — 5y
1
Since there was multiple parts in a model it was only looking at the name of the part not the model. I've fixed it so it destroys the parent of the part that is hit so it basically destroys the model now. Thanks for the help! iChaboyy 7 — 5y
Ad
Log in to vote
1
Answered by 5 years ago

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)
0
Woops, didn't see that @Paintertable has made it... Well both should work.. lmao XviperIink 428 — 5y
0
np :) Paintertable 171 — 5y
0
Thanks for atleast trying to help lol iChaboyy 7 — 5y

Answer this question