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

Where do I put the spawn function?

Asked by 9 years ago

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

Log in to vote
0
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
9 years ago

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.

0
I think I understand now :) Seeker5123 15 — 9y
0
Lol, I just realized I destroyed it XD Seeker5123 15 — 9y
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 Seeker5123 15 — 9y
Ad

Answer this question