Hi,
I am trying to spawn a part called “Log” through a button only if there isn’t already a part called “Log” in the workspace. I typed the code below but “Log” keeps spawning even though Log already exists in the workspace. Not sure why this is happening and there are no errors. Can someone explain the error?
local X = game.Workspace.Part.ClickDetector
local found = game.Workspace:FindFirstChild("Log")
if found == nil then
function onMouseClick()
local Log = game.ReplicatedStorage.Log:Clone()
Log.Position = Vector3.new(45.1, 0.5, 25.7)
Log.Parent = game.Workspace
Log.Transparency = .5
end
end
X.MouseClick:Connect(onMouseClick)
Using “=” is a way of making a statement in a line of code.
local A = 1
This is a statement that tells the rest of the script “Whenever A is mentioned, we’re talking about the number 1, just so everyone is clear and understands that.”
Using “==” is a way of “asking” the question “is equal to.”
local A = 1
print(A == 1)
This prints “true” because as mentioned earlier, when A is referenced, the whole script understands that we’re talking about the number 1. The script then compares A (1) to the number 1 and says it’s true that they’re equal to one another.