Part not appearing when it's supposed to

Hi everyone, so I was working on my project when I encountered a problem, a part is not spawning. From what I could see, Instance.new("Part", game.Workspace) appears to not be working. Here’s the section of the scripts that aren’t working

Local script :

buildTool.Activated:Connect(function()
	print("A")
	script.Parent.BlockPlacedEvent:FireServer("placeBlock", game.Players.LocalPlayer:GetMouse().Hit.Position)
end)

Server script :

print("SA")
local part = Instance.new("Part", game.Workspace)
print("C")
part.Parent = game.Workspace
print("W")
part.Anchored = true
part.Size = size	
part.Position = Vector3.new(math.floor(value.X / size.X) * size.X, value.Y + size.Y / 2, math.floor(value.Z / size.Z) * size.Z)

This is just the section of the code that’s not working, I’ll be happy to send the full script if need be. For your information, the print functions all occur but the part just doesn’t even appear, not just transparent or parented to something else but just gone. Help would be greatly appreciated.

Note: There are no error messages in the output

1 Like

Try Instance.new() in the LocalScript. Also, don’t do this:

local part = Instance.new("Part", game.Workspace)

Do this instead:

local part = Instance.new("Part")
part.Parent = game.Workspace

local part = Instance.new(“Part”, game.Workspace)

you shouldn’t use the parent argument inside Instance.new check this out. Instead parent the part with part.Parent.

Also could you please show me the full script so I can see the variables

1 Like

You aren’t setting the position of this part.

1 Like

You don’t use Instance.new() on the client, else it won’t replicate on the server.

It may be that you’re missing one parameter from the RemoteEvent on the server. When you fire a remote event, you can pass variables through, but the first parameter you will receive is always the player.

Ex:

FireServer(var1, var2, var3)

OnServerEvent(player, var1, var2, var3)

Unless he wants everyone to see the part, in which case it belongs on the server.

He’s setting the position on the last line.

You should print the position of the part as soon as you set the position.

The link leads to :
Screenshot 2022-10-25 at 8.18.58 PM

The part doesn’t even exist, at least I can find it

  1. I got every parameter
  2. I don’t get how it would affect it
1 Like

Well, try setting the parent of the part only after you anchor and position it. It might be because it’s falling into the void, but I don’t see how that’s possible since no physics has happened before you anchor it. It could still be a fix though!

If you have have forgotten to include the player parameter, it would result you setting the position to something else because you reference another parameter

If that happens then I’m quite sure I would have already seen the error message by now

1 Like

I appreciate your help but nothing seemed to change

I’m not sure if this is what it’s supposed to be. I get the player variable from assuming that your server script is inside the tool. It works for me, but the blocks are spawning inside another. To fix that, you can use a script for surface, for example, in the remote parameter argument from localscript, use mouse.TargetSurface, then in the server script, use that argument like, if surface == Enum.NormalId.Front then part.Position = thisVector3

local character = script.Parent
local player = game.Players:GetPlayerFromCharacter(character)

script.Parent.BlockPlacedEvent.OnServerEvent:Connect(function(player,aString,value) -- assuming value is the mouse.Hit position argument that came through
	print("SA")
	local part = Instance.new("Part", game.Workspace)
	print("C")
	--part.Parent = game.Workspace (you are parenting it twice which is already in the new instance parameter)
	print("W")
	part.Anchored = true
	
	local size = Vector3.new(4,4,4) --size (assuming the size is 4x4x4)
	
	part.Size = size
	part.Position = Vector3.new(math.floor(value.X / size.X) * size.X, value.Y + size.Y / 2, math.floor(value.Z / size.Z) * size.Z)
end)

Here’s the full script :

local size = Vector3.new(4, 4, 4)

script.Parent.BlockPlacedEvent.OnServerEvent:Connect(function(plr, use, value)
	if use == "sizeChange" then
		size = value
	elseif use == "placeBlock" then
        <!--Start from here-->
		print("SA")
		local part = Instance.new("Part", game.Workspace)
		print("C")
		print("W")
		part.Anchored = true
		part.Parent = game.Workspace
		part.Size = size
		part.Position = Vector3.new(math.floor(value.X / size.X) * size.X, value.Y + size.Y / 2, math.floor(value.Z / size.Z) * size.Z)
	end
end)

It’s best if you don’t parent your part yet in the new instance parameter before anchoring it because if the server is fast, the block will fall before it gets anchored. Do your part.Anchored = true first then part.Parent = workspace. In the new instance, just do Instance.new(“Part”) without the parenting.

game.Workspace can be written in just workspace lowercase

1 Like

Okay, wow, my guess 4x4x4 was right, and also value is the position you passed through. Just remove the parent inside your new instance. It’s working for me.

Side note : For some reason, I always have to equip and unequip it for it to work