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

I need help with CFraming a Part's Y Position?

Asked by 7 years ago

So, I'm trying to make a script that when the Player presses "e', It creats a Part and the Part goes to antoher part called "Buidling". My problem is that I need the Part to go to a certain Y Postion depending on the Player's Torso's Y Postion. So like if the Player is at a certain height, the Part will be a higher than the Player's height. But I need it so that the Part's Y Position will never pass the Building's height. Any idea how to do that?

Thank's in advance (And sorry if I sound confusing... it's really hard to explain.)

1 answer

Log in to vote
0
Answered by
kazeks123 195
7 years ago
Edited 7 years ago

You should thank me a lot since I basically wrote the script for you:

01uis = game:GetService("UserInputService") --Getting input service
02player = game.Players.LocalPlayer --Getting player
03part = nil --Variable for your part
04buildingHeight = 20 --Your building height (building's top Y coordinate)
05building = game.Workspace.building --Your building
06 
07 
08uis.InputBegan:connect(function(input) --Getting player's inputs
09    if input.KeyCode == Enum.KeyCode.E then --Checking if E key was pressed
10        part = Instance.new("Part") --Creating new part
11        part.Anchored = true
12        part.CanCollide = false --Optional property if you don't want player to be pushed by part
13        part.Parent = game.Workspace --Getting part to workspace
14        part.CFrame = player.Character.Torso.CFrame * CFrame.new(0,3,0) --Teleporting part 3 studs above player's torso
15        part.Orientation = Vector3.new(0,0,0) --Resetting part's rotation
View all 22 lines...

This will get part in the building's center (add offset to the Vector3 in line 20 if you don't want the part to be in the building brick) 3 studs above player's torso's position or at the top of building if player is above it. It MUST be placed in a LocalScript to work, which has to be placed in the player's character's model (or StarterPack / StarterGui).

0
Thank you MRbraveDragon 374 — 7y
Ad

Answer this question