Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

This code does not insert a BodyPosition for some reason?

Im trying to move a player, so im using a BodyPosition, but when i use it, it does not insert a BodyPosition. There are no errors, so I do not understand why it does not work. Here is my script.

local head = player:WaitForChild('Head')
v = true
print("Fall mode")
workspace.CurrentCamera.CameraType = "Custom"
Player:LoadCharacter()
local character = Player.Character
if not character or not character.Parent then
	character = Player.CharacterAdded:wait()
end
print("tp")
local Force = Instance.new("BodyPosition")
		
Force.Parent = character:WaitForChild("Head")
head:WaitForChild("BodyPosition").Position.X = Player.PlayerGui.FreeCam.PlaceHolder.Value.X
head:WaitForChild("BodyPosition").Position.Y = Player.PlayerGui.FreeCam.PlaceHolder.Value.Y
head:WaitForChild("BodyPosition").Position.Z = Player.PlayerGui.FreeCam.PlaceHolder.Value.Z
print("done")
repeat wait(1) until math.floor(head.Position.X) == math.floor(Player.PlayerGui.FreeCam.PlaceHolder.Value.X) and math.floor(head.Position.Y) ==math.floor(Player.PlayerGui.FreeCam.PlaceHolder.Value.Y) and math.floor(head.Position.Z) ==math.floor(Player.PlayerGui.FreeCam.PlaceHolder.Value.Z) --This gets the head's position and matching it with my value i want it to be. I'm using math.floor in case there are any decimals. 
wait(1)
print('Done!')
head.BodyPosition:Destroy()

In case you are wondering, Player is already defined. It is the player in the players list. This is in a server script if you need to know for something I don't already know.

5 comments

0

Instance.new("BodyPosition", head) instead of Instance.new("BodyPosition").Parent = head

0

Doing Instance.new("BodyPosition", head) would still do the same thing as Instance.new("BodyPosition").Parent = head. Also, using your way still does not work.

0

It's NOT The same thing...

0

whats the difference

0

Using :MoveTo() will move a model so maybe this will work. Put a block where you want the player to go and do this. Character:MoveTo(block.Position)

1 answer

✓ Accepted answer

CurrentCamera is not accessible with a server script.

It will be the base camera clip in the game, not the player camera.

Also, there are a lot more efficient ways to spawn and edit the body force.

So I would change this to a local script and edit how you spawn in the force (although it should work, its not very clean and efficient)

local head = player:WaitForChild('Head')
v = true
print("Fall mode")
workspace.CurrentCamera.CameraType = "Custom"
Player:LoadCharacter()
local character = Player.Character
if not character or not character.Parent then
    character = Player.CharacterAdded:wait()
end
print("tp")
Force = Instance.new("BodyPosition") -- dont use a parent modifier and give it a delay to enter the game to avoid load-in lagg.
Force.Position = Vector3.new(Player.PlayerGui.FreeCam.PlaceHolder.Value)
Force.Parent = character:WaitForChild("Head")
repeat wait(1) until math.floor(head.Position.X) ==math.floor(Player.PlayerGui.FreeCam.PlaceHolder.Value.X) and math.floor(head.Position.Y) ==math.floor(Player.PlayerGui.FreeCam.PlaceHolder.Value.Y) and math.floor(head.Position.Z) ==math.floor(Player.PlayerGui.FreeCam.PlaceHolder.Value.Z) --This gets the head's position and matching it with my value i want it to be. I'm using math.floor in case there are any decimals. 
wait(1)
print('Done!')
head.BodyPosition:Destroy()

2 comments

0

Thanks! Also, i still did this with a server script and it works

0

Also, how would you change the BodyPosition's position?

This discussion is preserved as it was. New answers, comments, and votes are closed.