Teleporting part to Local Player not working?

Hi!

I’m trying to achieve a script that teleports a part to a player with a head transparency of 0.3
All help is appreciated :smiley:

My code so far

local Part = script.Parent
local plr = game.Players.LocalPlayer
while true do
Part.Position = CFrame.new(plr.Character.Torso.Position)
wait()
end

1 Like

You cannot change the position of parts on the server from a local script.
And you cannot get the LocalPlayer from a server script.

What you can do is either:

  • Do everything from the server on a server script

or

  • Use a remote event
1 Like

You’ve got a few problems. Firstly, LocalScripts don’t run in Workspace so it’ll never actually do anything. Secondly, parts you move on the client don’t replicate to the server. So if you have the script in the correct place and index the part, it’ll only move for that player. You’ll have to change the position on the server if you want it to replicate. Thirdly, you’re trying to set the Position to a CFrame, that doesn’t work. You can either set the parts CFrame or use the Torso position (CFrame is probably better for your application).

I just edited my post, how could I do that instead?

How do you know the local script is in the workspace?

Because the script is in the part. The only logical place a part would move is within Workspace

Do you want it to replicate to other players or is it a local part?

I don’t know, either works. Basically, I’m just trying to make it so it teleports the part to a player with a head transparency of 0.3.

Do you want it to only be visible by the player, or to be visible by every player in the game (every player can see other players’ parts)?

Instead of making the part have a script under it, put the following script into starter character scripts:

local Character = script.Parent
local Part = workspace.Part
while true do
    Part.Position = Character.Torso.Position
    wait()
end
1 Like

Visible to every player would be good.

Ok, so you need to use a server script to control the parts as the parts would need to be on the server.

Please make sure to use the correct syntax for source codes on this forum which looks like shown:

--Code here

image
Next, there is not really enough information for me to understand what exactly do you need, please be more specific on a thing when you said that you’d like to teleport a part to a player with head transparency 0.3 which you do not even change any transparency inside of the script. You can only call, LocalPlayer like you did, inside of local script, on the normal script is not going to work. I’d strongly not recommend using only wait() since it was approved that some false and negative disturbances may happen if you use it, inside of this article. I’d rather use wait(n) which is more sufficient way of declaring the wait time for instance: wait(0.1) should be good enough and there shouldn’t be any eye seen changes. The source code you sent, all the changes are going to be visible only for the local player since you use the local script if you’d like to have changes seen by other players in the game as well, I’d highly recommend using RemoteEvents and do the things you need to be seen for all the players on the server script. I’d hint that firing the server from client side the first argument on the server-side is automatically a local player from which event was fired.