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

Where do I put the spawn function?

I'm very confused, can someone please help me figure out where to put the spawn function to spawn the spear? I'm making a game which involves crafting and really need all the help I can get.(Did I put it in the right place?)

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

1 answer

✓ Accepted answer

You really need to solidify more of your basics before going and making a crafting system.


The function will never run, because it's never called (read the wiki link for more info on functions). However, it would never even get created, because you destroy the script right before it!


Lua is read left to right, top to bottom. This means that if you want something to happen in a certain order, just put it in that order! In other words, if you want A to be executed before B, all you need to do is put B below or to the right of A in the script editor.

function func1()
	--Do stuff
end 

function func2()
	--Do stuff
end

func1()
func2()

func1 is now executed first because we called it first.

print("Hi")
print("Hola")

"Hi" prints before "Hola"

The same thing applies to your code.

3 comments

0

I think I understand now :)

0

Lol, I just realized I destroyed it XD

0

Would this work? @Perci1 function spawn()local Spear=Instance.new("Part", game.Workspace) --Shape/Size/Color Spear.CFrame=CFrame.new(Part.Position) script.Parent.Touched:connect(function(Part) if Part.Name=="Stick" and script.Parent.Name=="PointedStone" then workspace.Stick:remove() workspace.PointedStone:remove() end end) end end) function spawn() script.Parent:remove

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