I have a script where when the two required parts touch each other they're supposed to be removed, and in their place is a new part/tool, I've tested it time and time again, and tried at least 20 scripts. Please help me!
script.Parent.Touched:connect(function(Part) if Part.Name=="Stick" and Part.Name=="PointedStone" then workspace.Stick:remove() workspace.PointedStone:remove() end end) script.Parent:remove() local Spear=Instance.new("Part", game.Workspace) --Adjust shape/color/size of product item here.
There are multiple errors in this script we will run through.
Firstly, I want you to take a look at this if statement explanation.
The if statement you have is impossible. Let's take a look at it and put it in English.
if Part.Name=="Stick" and Part.Name=="PointedStone" then
Translated to a real life situation this would be:
If my name is Drake, and my name is Ben, then...
It's impossible. You only have one name, and can only index one name. I know what you are trying to accomplish, so let me try to assist a bit
if script.Parent.Name=="Stick" and Part.Name=="PointedStone" then
We can also switch this and say:
if Part.Name=="Stick" and script.Parent.Name=="PointedStone" then
Or, you could only put this script inside Sticks and PointedStone's, then only have 1 condition such as;
if Part.Name=="Stick" then
or;
if Part.Name=="PointedStone" then
In your current script, you don't have the spawn inside the if, which will cause the spear to spawn no matter what, whenever the script is ran (on server startup).
As You can see I have added the CFrame.new
to get the Position of the Part.
script.Parent.Touched:connect(function(Part) if Part.Name=="Name1" and Part.Name=="Name2" then Part:remove() script.Parent:remove() local Spear=Instance.new("Part", game.Workspace) Spear.CFrame=CFrame.new(Part.Position)--My change end end)
If this helped please Accept Answer and Upvote!