I'm trying to create a instance so a part in my game will spawn when another part is click, here's what I have so far...
local ball = game.Workspace.Fifa Ball function onClicked() local brick = Instance.new("Part", game.Workspace) brick.Name = "Fifa Ball" end script.Parent.ClickDetector.MouseClick:connect(onClicked)
Ok, i think i understand what you are trying to do. And i will tell you where you went wrong. When declaring variables there are two types, Global and Local. Local variables can only be used when inside of a function. So that was the first Mistake. Secondly, if you have a space in the object declared in the variable, its slightly more complicated. it should look like this if you want a space
ball = game.Workspace.["Fifa Ball"]
It is much easier to use no spaces. The final product should turn out like this
function onClicked() local brick = Instance.new("Part", game.Workspace) brick.Name = "FifaBall" end script.Parent.ClickDetector.MouseClick:connect(onClicked)
You can put this script inside any part along wit ha ClickDetector for it to work. You can even take steps further and manipulate the location of the brick upon its spawning.
****Hope This helped you :D
2 Problems
Problem 1:
You variable is not meant to have a gap. The script reads it as FifaBall rather than Fifa Ball. The way to do this is by adding [ ] with a string inside of it... Like so.
local ball = game.Workspace["Fifa Ball"] -- Remember, there is no "." between "workspace" and ["Fifa Ball"]
Problem 2:
The other thing is. Naming a part should be in brakets. Using ( ) with a string inside will work.
local ball = game.Workspace["Fifa Ball"] function onClicked() local brick = Instance.new("Part", game.Workspace) brick.Name = ("Fifa Ball") end script.Parent.ClickDetector.MouseClick:connect(onClicked)
Hoped it helped!
--//Myaxp