Creating a Simple Room Script

I’m working on a script a script with a platform, and when you touch a small part on a side of the platform, another platform is cloned or spawns. This doesn’t work though as the output says “ServerScriptService.Script:9: attempt to perform arithmetic (add) on nil and Vector3.” I’ve tried to fix this by using for loops and bringing all the parts, but even majorly extending the script to an excessive amount hasn’t worked. I’m think this script may require a more advanced kind of script. This script is also for only one of the sides.

local RS = game:GetService("ReplicatedStorage")
local Flooring = RS:WaitForChild("Flooring")
local debounce = false
game.Workspace.Flooring.TouchPart1.Touched:Connect(function()
	if debounce == false then
		Flooring:Clone()
		Flooring.Parent = workspace
		local FlooringChildren = Flooring:GetChildren()
		FlooringChildren.Position += Vector3.new(0,0,15)
	end
end)

1 Like

I think you don’t add. You do this

FlooringChildren.Position = Vector3.new(FlooringChildren.Position.X, FlooringChildren.Position.Y, FlooringChildren.Position.Z + 15)

Wrote this on mobile so there might be errors but, I think it’s correct, try it out! I did plus 15 because you’re adding 15 to your z plane on your original script.

The output says “ServerScriptService.Script:9: attempt to index nil with ‘X’”

Try to rewrite it because autocorrect will autocorrect it

That was essentially the exact same thing you were doing.

The problem is that you’re trying to add a Vector3 to a table.

How to fix your issue

Hello, it appears you are trying to get the position of a objects children. You can see that you called for its children by doing

Flooring:GetChildren() -- gets the children of "Flooring"

The children of a part represent all the objects located inside of it:

image

However, you cannot get the position of the children. What you have to do is either get the model position or an individual part position.

You can get the middle position of a model by doing:

local FlooringChildren:GetPivot().Position -- If its a model

or for an individual part

local FlooringChildren.Position -- if its a part
2 Likes
local RS = game:GetService("ReplicatedStorage")
local Flooring = RS:WaitForChild("Flooring")
local debounce = false
game.Workspace.Flooring.TouchPart1.Touched:Connect(function()
	if debounce == false then
		debounce = true
		Flooring:Clone()
		Flooring.Parent = workspace
		local FlooringChildren = Flooring:GetPivot()
		FlooringChildren.Position = FlooringChildren.Position + Vector3.new(0,0,15)
		debounce = false
	end
end)

I did this but it said position cannot be assigned to in the output.

What you are doing

local Flooring = RS:WaitForChild("Flooring")
Floor:Clone() -- Is not stored in a variable

Instead do

local Flooring = RS:WaitForChild("Flooring")

-- Store Floor:Clone() in variable
local floorClone = Flooring:Clone() 

and store it in a variable. Then when you want to change things about the clone you would do stuff like

local Flooring = RS:WaitForChild("Flooring")

-- Store Floor:Clone() in variable
local floorClone = Flooring:Clone()

-- Set Parent of clone 
floorClone.Parent = workspace
local RS = game:GetService("ReplicatedStorage")
local Flooring = RS:WaitForChild("Flooring")
local FClone = Flooring:Clone()
local debounce = false
game.Workspace.Flooring.TouchPart1.Touched:Connect(function()
	if debounce == false then
		debounce = true
		FClone.Parent = workspace
		local FlooringChildren = FClone:GetPivot()
		FlooringChildren.Position = FlooringChildren.Position + Vector3.new(0,0,15)
		debounce = false
	end
end)

I did this but it still said position cannot be assigned to in the output. I’m gonna try using originposition.

I made the part spawn in the proper position, but I need it to repeat for the cloned part. Would you know how to do that?

FlooringChildren is not the Child of the Floor. but an array of children instances of it.
If you want to get the correct Child you need to use
Flooring:FindFirstChild("Child_Name"),
Flooring.Child_Name or Flooring:GetChildren()[1]

also on another thing you have to have a variable for Floor:Clone()

while this solves the error issue, I do not know much about what You are trying to achieve

Do any of you know how I can apply addition to MoveTo? Like do you know how I can add position each time a function runs each time I use MoveTo. (I made it infinite lets go!!!)