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.)
You should thank me a lot since I basically wrote the script for you:
01 | uis = game:GetService( "UserInputService" ) --Getting input service |
02 | player = game.Players.LocalPlayer --Getting player |
03 | part = nil --Variable for your part |
04 | buildingHeight = 20 --Your building height (building's top Y coordinate) |
05 | building = game.Workspace.building --Your building |
06 |
07 |
08 | uis.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 = Vector 3. new( 0 , 0 , 0 ) --Resetting part's rotation |
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).