Okay, so I want to move a model in front of my torso, but that's not working though :P
local m = game.Players.LocalPlayer:GetMouse() local character = game.Players.LocalPlayer.Character local Torso = game.Players.LocalPlayer.Character.UpperTorso local active = false local IceShield = script.IceShield local position = Torso.Position + Torso.CFrame.lookVector * 5 db = true m.KeyDown:connect(function(k) k = k:lower() if k == 'x' then IceShield:Clone().Parent = game.Workspace IceShield:MoveTo(position) end end)
MoveTo
to move a model, it can cause weird behaviour, such as teleporting to the sky. Set a PrimaryPart
on your model and use SetPrimaryPartCFrame
. Also, you're recording the position before the key is pressed, so the first position is when the character first spawns. Record the position in the event.Mouse.KeyDown
and connect
are deprecated, switch to UserInputService
and Connect
instead.local UserInputService = game:GetService("UserInputService") local player = game:GetService("Players").LocalPlayer local character = player.Character or player.CharacterAdded:Wait() local Torso = character.UpperTorso local active = false local IceShield = script.IceShield UserInputService.InputBegan:Connect(function(input, isChatting) if input.KeyCode == Enum.KeyCode.X and not isChatting then if not char.Humanoid.Jump then -- if the key is X, not chatting, and not jumping we do the following local IceClone = IceShield:Clone() IceClone.Parent = game.Workspace IceClone:MakeJoints() -- make sure it doesn't fall apart! IceClone:SetPrimaryPartCFrame(Torso.CFrame + Torso.CFrame.lookVector*5) end end end)
You need to put
local position = Torso.Position + Torso.CFrame.lookVector * 5
inside the keydown event. This is done because when it is outside of the event, the value of that stays the same even after the character has moved position. When it's inside the keydown event, the position is calculated right when they press it.