Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

This code does not insert a BodyPosition for some reason?

Asked by 6 years ago
Edited 6 years ago

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.

0
Instance.new("BodyPosition", head) instead of Instance.new("BodyPosition").Parent = head Sekant 20 — 6y
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. hiimgoodpack 2009 — 6y
0
It's NOT The same thing... Bellyrium 310 — 6y
0
whats the difference hiimgoodpack 2009 — 6y
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) goldstorm950 65 — 6y

1 answer

Log in to vote
0
Answered by
Bellyrium 310 Moderation Voter
6 years ago
Edited 6 years ago

CurrentCamerais 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()
0
Thanks! Also, i still did this with a server script and it works hiimgoodpack 2009 — 6y
0
Also, how would you change the BodyPosition's position? hiimgoodpack 2009 — 6y
Ad

Answer this question