Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why won't my crafting script work?

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.

2 answers

✓ Accepted answer

There are multiple errors in this script we will run through.

Firstly, I want you to take a look at this if statement explanation.



##Error 1: Impossible If Statement.

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


##Error 2: Spear Spawn

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).

4 comments

0

Thanks, I'm gonna test it again later tonight, hope it works :)

0

Spawn? Can you please elaborate, I'm confused.

0

See how you create a new part in workspace OUTSIDE of the event? That's what he's talking about. Your "Spear" will spawn (come into existence; get created) immediately when the server starts, no matter what.

0

Like this? script.Parent.Touched:connect(function(Part) if Part.Name=="Stick" and script.Parent.Name=="PointedStone" then workspace.Stick:remove() workspace.PointedStone:remove() end end) script.Parent:remove() function spawn()local Spear=Instance.new("Part", game.Workspace) --Adjust shape/color/size of product item here.1 Spear.CFrame=CFrame.new(Part.Position)--My change

Added

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!

6 comments

0

Thanks :)

0

Sorry for a Bad Description, I had nothing really to say, and I was also afraid that Someone might beat me.

0

It's all good.

0

Btw, I didn't down vote you

0

do you mind upvoting me :(

0

Not enough rep. Joined yesterday :(

This discussion is preserved as it was. New answers, comments, and votes are closed.