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

Why won't my crafting script work?

Asked by 9 years ago

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

Log in to vote
3
Answered by 9 years ago

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

0
Thanks, I'm gonna test it again later tonight, hope it works :) Seeker5123 15 — 9y
0
Spawn? Can you please elaborate, I'm confused. Seeker5123 15 — 9y
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. Perci1 4988 — 9y
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 Seeker5123 15 — 9y
Ad
Log in to vote
-2
Answered by
woodengop 1134 Moderation Voter
9 years ago

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!

0
Thanks :) Seeker5123 15 — 9y
0
Sorry for a Bad Description, I had nothing really to say, and I was also afraid that Someone might beat me. woodengop 1134 — 9y
0
It's all good. Seeker5123 15 — 9y
0
Btw, I didn't down vote you Seeker5123 15 — 9y
View all comments (2 more)
0
do you mind upvoting me :( woodengop 1134 — 9y
0
Not enough rep. Joined yesterday :( Seeker5123 15 — 9y

Answer this question