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

How do I set the position of a model to directly under them, regardless of their Y position?

Asked by 5 years ago
Edited 5 years ago

Okay so hopefully my question makes sense, but I'll explain it. What I have tried, yet failed to do is clone a model from the workspace, and set the position to directly under the player, but if a player jumps for example, the model just clones to under their feet, but in the air, however I want it to be flat on whatever part is underneath them. In addition, if the player is walking then the model gets cloned behind them too, which is something I can't seem to fix, so if I could have assistance with that too then I'd really appreciate it.

local rs = game:GetService("ReplicatedStorage")
local CAS = game:GetService("ContextActionService")
local trap = rs:WaitForChild("BearTrap")
local event = rs.Events:WaitForChild("placeBT")

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local inGame = plr:WaitForChild("inGame")
local traps = plr:WaitForChild("Traps")

local function placeTrap(actionName, inputState, inputObj)
    if inputState == Enum.UserInputState.Begin and traps.Value >= 1 then
        event:FireServer(plr.Traps)
        rs.BearTrap.CreatedBy.Value = plr.Name
        trap:Clone().Parent = workspace
        local pos = char["LeftFoot"].Position
        trap:SetPrimaryPartCFrame(CFrame.new(pos))
    else
        return
    end
end

CAS:BindAction("Trap Placement", placeTrap, false, Enum.KeyCode.F)

I appreciate you reading this, and any assistance is welcome and appreciated!

0
this might help:https://scriptinghelpers.org/questions/8727/how-can-i-use-moveto-on-a-model-and-have-it-cframe-into-parts ForgotenR4 68 — 5y
0
local pos = char["LeftFoot"].Position * Vector3.new(1,0,1) greatneil80 2647 — 5y
0
Raycast vertically down from their torso, and create it wherever the ray hits. fredfishy 833 — 5y
0
I have tried both, however the first answer just did the same thing as before, and the second answer placed them under the player, but all at 0 on the Y axis, however I meant to place them flat on the part directly beneath the player, regardless of the Y axis. Cynmorphic 0 — 5y
View all comments (4 more)
0
@fredfishy I'm not entirely sure on how to do that, I've read up on raycasting but it's far too advanced for me. Cynmorphic 0 — 5y
0
For line 17, trap:SetPrimaryPartCFrame(CFrame.new(pos)), Have you tried adding a Vector3? If you haven't, try changing it to trap:SetPrimaryPartCFrame((CFrame.new(pos)) + Vector3.new(0,-1,0) change Y (-1) to your value. LennyPlayzYT 269 — 5y
0
or you could try in line 16, local pos = char["LeftFoot"].Position + Vector3.new(0,-1,0), Set Y (-1) to your Val, which each whole number descending is worth 1 stud. Or, try local pos = char["LeftFoot"].Position - Vector3.new(0,1,0) Change Y (1) to your value, as each whole number ascending is 1 stud descending, as it said local pos = char["LeftFoot"].Position with the subtract. LennyPlayzYT 269 — 5y
0
Yeah, however if the player jumps and presses it, then the model will still be floating in the air Cynmorphic 0 — 5y

Answer this question