Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why isn't the player levitating?

This script is supposed to levitate the player I click on, but it doesn't do anything, no errors or anything.

plr = game.Players.LocalPlayer
chr = plr.Character or plr.CharacterAdded:wait()
mouse = plr:GetMouse()
target = mouse.Target

mouse.Button1Down:connect(function()
	if target and target.Name == "Torso" or target.Name == "Handle" or target.Name == "Right Leg" then
		local tar = game.Players:GetPlayerFromCharacter(mouse.Target.Parent)
		while true do
			game:GetService('RunService').RenderStepped:wait()
			tar.Character.Torso.Anchored = true
			tar.Character.Torso.CFrame = tar.Character.Torso.CFrame + Vector3.new(0,.5,0)
			tar.Character.Humanoid.WalkSpeed = 0
		end
	end
end)

2 comments

0

try moving the humanoidrootpart instead of the torso, after all, the torso is connected to the humanoidrootpart.

1

On line 4, you've got the target when the script Loads - not when you click, consequently, your 'target' doesn't update. - Try setting the target after mouse.Button1Down fires (inbetween line 6 and 7).

1 answer

After running your code in studio it the error seems to be on line 6 and 7.

mouse.Button1Down:connect(function()
    if target and target.Name == "Torso" or target.Name == "Handle" or target.Name == "Right Leg" then

If you look at the code but remove everything else you can see that you never get the whatever the mouse is targeting.

To fix this all you need to do is move line 4 down in between line 6 and 7 so that it checks to see if the mouse is targeting anything. (ROBLOX Studio would also recommend that you localize the target variable so localized it for you.)

mouse.Button1Down:connect(function()
	local target = mouse.Target
	if target and target.Name == "Torso" or target.Name == "Handle" or target.Name == "Right Leg" then

I put the full script fixed below:

plr = game.Players.LocalPlayer
chr = plr.Character or plr.CharacterAdded:wait()
mouse = plr:GetMouse()

mouse.Button1Down:connect(function()
	local target = mouse.Target
    if target and target.Name == "Torso" or target.Name == "Handle" or target.Name == "Right Leg" then
        local tar = game.Players:GetPlayerFromCharacter(mouse.Target.Parent)
        while true do
            game:GetService('RunService').RenderStepped:wait()
            tar.Character.Torso.Anchored = true
            tar.Character.Torso.CFrame = tar.Character.Torso.CFrame + Vector3.new(0,.5,0)
            tar.Character.Humanoid.WalkSpeed = 0
        end
    end
end)

If you have any questions, concerns or just need some help with this PM me on ROBLOX!

This discussion is preserved as it was. New answers, comments, and votes are closed.