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

Why isn't the player levitating?

Asked by 8 years ago

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)

0
try moving the humanoidrootpart instead of the torso, after all, the torso is connected to the humanoidrootpart. HungryJaffer 1246 — 8y
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). hiccup111 231 — 8y

1 answer

Log in to vote
0
Answered by
samfun123 235 Moderation Voter
8 years ago

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!

Ad

Answer this question