Help with script?

Hi there!

I want to make a telekinesis script similar to this:


You hold a keybind, for example e, on a player and they ragdoll and follow your mouse cursor. When you click, they get thrown. If you let go of e, they just drop.

How would I do this?

I’m aware i’d need to use

local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function()

etc

UIS.InputEnded:Connect(function()
etc

thanks for any help!

1 Like

when you click the input, cast a ray to the mouse’s position, but put a max ray length on the ray. then, insert a body position into the primary part of the model and set its position to the ray’s end point.

you may need to hook the inputs up to a renderstepped loop or a mouse position changed function in order to update the position of the model that’s being thrown around whenever the mouse moves.

this makes no sense to me… i’m not very good at scripting

oh… sorry haha. let me formulate something for you. :slight_smile:

1 Like

What I am assuming is that this was made by using the Player:GetMouse() function. Maybe some of these should help? Mouse / PlayerMouse / Mouse.Target / Player:GetMouse. Furthermore, you should try using BodyVelocity on a player to launch them anywhere when they point their mouse (or click their mouse) pointed at a certain character. Hope I helped!

1 Like

No offense, but you’ll probably have to spend some time learning before you can make a script like this. It’s pretty complicated.

I think I have found another solution to what you are trying to do. Maybe take a bit out of this post that I put here? Ability to click players?

So when they click on the player, you create a new instance which is called BodyVelocity and apply it to the player’s humanoidrootpart. After, add the Debris function which you get from game:GetService() . Make sure to use AddItem function when using Debris, because this is going to stop the bodyvelocity from going any longer.

Example here:
game:GetService('Debris'):AddItem(bv, 1)

I hope this did the trick.

EDIT: I mis-understood you. Instead, you want to drag the player and pretty much put them anywhere as if it was telekinesis, right? I have another post you can take a bit of info from. Dragging objects with the mouse

okay, paste this into a localscript inside of StarterPack.

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local uis = game:GetService("UserInputService")
local camera = workspace.CurrentCamera

local teleEnabled = false
local targetedModel = nil
local maxRange = 25

mouse.Button1Down:Connect(function()
	local target = mouse.Target
	if target and target.Parent:FindFirstChild("Humanoid") then
		teleEnabled = true
		targetedModel = target.Parent.PrimaryPart
		local bp = Instance.new("BodyPosition", targetedModel)
		bp.MaxForce = Vector3.new(5e5,5e5,5e5)
		bp.Position = player.Character.HumanoidRootPart.Position
	end
end)

mouse.Button1Up:Connect(function()
	teleEnabled = false
	if targetedModel and targetedModel:FindFirstChild("BodyPosition") then
		targetedModel.BodyPosition:Destroy()
	end
	targetedModel = nil
end)

mouse.Move:Connect(function()
	if teleEnabled == true then
		if targetedModel then
			local location = camera.CFrame.Position + (mouse.Hit.Position - camera.CFrame.Position).Unit * maxRange
			targetedModel.BodyPosition.Position = location
		end
	end
end)

this works on any model with a set PrimaryPart and Humanoid.

1 Like

won’t this only show for me? i thought local scripts were clientsided
nevermind

Since this utilizes BodyMovers, it shows on all clients.