How would I make a part move to me if I press the key 1?

So I’m tryna make a part come to me when I press the key 1

How would I do this?

The part is named “FollowPart” btw. sending scripts help, anything helps! :smiley:

1 Like

You can just use UserInputService, which fires a RemoteEvent, that will activate a TweenAnimation for a certain part.

local User = game:GetService("UserInputService")

User.InputBegan:connect(function(key)
    if key.KeyCode == Enum.KeyCode.One then
   FollowPart.Position = Game.Players.LocalPlayer.Character.HumanoidRootPart.Position

   end 
end)

i dont think its the best but the part will only teleport to you

1 Like

and this also will happen only to you, I mean, UIS works only from the Client side so he will need to use some RemoteEvents to transfer the action to the ServerSide

I got bored so I am posting the entire thing you need here:

LocalScript:

local UIS = game:GetService("UserInputService")
local Remote = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")

local debounce = false

UIS.InputBegan:Connect(function(input, gpe)
	if not gpe then -- if not typing in chat.
		if input.UserInputType == Enum.UserInputType.Keyboard then
			if input.KeyCode == Enum.KeyCode.One and not debounce then
				debounce = true
				Remote:FireServer("MovePart")
				wait(1) -- prevents remote spamming.
				debounce = false
			end
		end
	end
end)

Server script:

local Remote = Instance.new("RemoteEvent")
Remote.Parent = game:GetService("ReplicatedStorage")

local TweenService = game:GetService("TweenService")

Remote.OnServerEvent:Connect(function(player, text)
	if text == "MovePart" then
		local HRP = player.Character.HumanoidRootPart
		local offset = Vector3.new(5,0,3) -- or whichever location around the player.
		local part = workspace.Part -- or wherever its at.
		local newTween = TweenService:Create(part, TweenInfo.new(1), {
			CFrame = CFrame.new(HRP.Position + offset, HRP.Position)
		})
		newTween:Play()
	end
end)

You will need to make some changes but yea here is the gist of it. Enjoy :sunglasses:

2 Likes

Alright thanks do I need remote events and where do I put the scripts?

I assumed you would have known this much with such a scripting question being a tad bit on the advanced side but I will help you out anyway.

The LocalScript is client sided, because UserInput is handled by the client. So you can put it anywhere that is client sided such as StarterGui for example which is my usual go-to for local scripts because its the most simplistic location to work from.

The server script goes inside ServerScriptService. It will automatically create a remote event for you.

1 Like

Okay thanks man! :heart: I really really thank you.

You’re welcome. Also dont forget to mark my reply as the solution to the post. :+1:

1 Like