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!
2 comments
try moving the humanoidrootpart instead of the torso, after all, the torso is connected to the humanoidrootpart.
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).