Help with positioning part

Hm, the problem still persist. I look in the output and see no errors but nothing seems to happen.

Is there a place where I should put the script specifically? or am I missing something?

Here is what I tried to change.(I also added some stuff but I don’t know if that effects)


--local script
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")
		
RemoteEvent:FireServer(Vector3.new(0,20,0))

--script

 ReplicatedStorage = game:GetService("ReplicatedStorage")

 RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")

local Part = Instance.new("Part")

 function PartPositioning(Player,NewPosition)
	
	local RootPart = Player.Character.PrimaryPart
	
	Part.Anchored = true
	
	Part.Position = RootPart.Position + NewPosition
	
	Part.CanCollide = false
	
	Part.Size = Vector3.new(10,10,10)
	
	
end


--Calls on function when player fires the remoteEvent

RemoteEvent.OnServerEvent:Connect(PartPositioning)

Try adding print() statements in order to debug, for example:

function PartPositioning(Player, NewPosition)
        print("Reached PartPositioning function!")
	local RootPart = Player.Character.PrimaryPart
	Part.Anchored = true
	Part.Position = RootPart.Position + NewPosition
	Part.CanCollide = false
	Part.Size = Vector3.new(10,10,10)	
end

Also ensure the LocalScript is not in Workspace, because LocalScripts do not run if they are in Workspace.

What does it mean when nothing prints?

That means that the function is never called, so most likely the RemoteEvent is not being fired.

Is the part that you instanced parented to the workspace? :thinking:

yes, I do have the Part parented to the workspace.

So you see the part but it doesn’t move?

The part doesn’t appear at all for some weird reason.

That means it isn’t parented you need to do Part.Parent = workspace in the function

I did uh local Part = Instance.new(“Part”,workspace)
does that achieve the same thing?

I didn’t saw that in the script well yeah you can also do that

Yes, that achieves the same thing but it is better to parent on a new line.

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

is better than

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

Here are some reasons why: PSA: Don't use Instance.new() with parent argument

1 Like

Hm, I would assume it won’t work because of where I placed it, I put the local script is StarterPlayerScripts

I also put the regular script in the remote function itself

Using dot syntax for indexing contents of ReplicatedStorage works perfectly fine, contents of ReplicatedStorage exist implicitly and are replicated by the time local scripts execute. No need for :WaitForChild() here

I just ran a few tests of my own and I tried to set up the scenario as I believe you have it set up. The problem I found was the part appeared not to be there, so I went to the explorer and realised the part was there, just at a completely different Y-value than I was expecting. This is because the local script executes as soon as it can, at which time the player’s character is still in the air (when you start a game the player spawns in the sky and drops down). I fixed the problem by adding a wait(2) before firing the RemoteEvent in the local script. Obviously this is not ideal and players will have varying loading times, however it showed what the problem for me was: the RemoteEvent is firing too early. Try putting a wait(3) before firing the RemoteEvent and see if it fixed your problem.

Nope, I looked in the workspace while firing and a part wasn’t created still so I tried increasing the wait time to 10 but nothing still appeared. This is really weird.

Try putting the regular script in the workspace instead and keep the remote event in replicated storage.

It worked, do you know if there is a reason to why I need to have the normal script placed in the workspace?

Scripts and LocalScripts will not run when they are parented to ReplicatedStorage

Source: API Reference on ReplicatedStorage

Thank you for the response and your time.

1 Like