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

How to make the torso anchor properly?

Asked by
hh9man 5
6 years ago

So earlier i asked how i could make the character stop while throwing a fireball. So i tried to anchor the torso like this, but it doesn't seem to work. Any help would be appreciated.

local Player = game.Players.LocalPlayer
local torso = Player.Character:FindFirstChild("Torso")
local Mouse = Player:GetMouse()
local RemoteEvent = game.Workspace.Fired
local UIS = game:GetService("UserInputService")

local Debounce = false

UIS.InputBegan:Connect(function(Input)
    if Input.KeyCode == Enum.KeyCode.R then                                         
        if Debounce == true then return end
       torso.Anchored = true
    wait (0.5)
       torso.Anchored = false   
        RemoteEvent:FireServer(Debounce)
    end
end)

1 answer

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

Hello, hh9man.

Possible reasons for your problem:

  1. You are running the game at r15, in which the Player's Character have different body parts--Torso which is divided into UpperTorso and LowerTorso,

  2. If you are running at r15, I suggest changing the anchor part to the whole character's body:

for i = 1, #parts do
        if (parts[i].ClassName == "MeshPart") then
            parts[i].Anchored = true
        end
    end
--Feel free to use this to replace line 12 in your script and just change Anchored = false in line 14
  1. If you just want to make the player's character stop moving, I suggest trying to change its Walkspeed instead of Anchoring.
local humanoid = Player.Character:WaitForChild("Humanoid") -- use WaitForChild as it properly waits until it loads, some script loads faster causing it to run first even without the object thereby causing it to break.
local walkspeed = humanoid.WalkSpeed

--The reason for using a -100 and +100 is because your game might have people using different walkspeed, some are faster and some are slower.
walkspeed = walkspeed - 100 -- this turns their walkspeed into negative so it prevents them from moving

walkspeed = walkspeed + 100-- this turns their walkspeed back to positive, back to their old walkspeed.

  1. You can always try to find the root of your problem yourself by testing it in a "Test"->"Local Servers "->"1 Player", and always have the Output bar on as it records all the scripts running and if something goes wrong it is immediately recorded their.
0
I tried your first method but it said Players.hh9man.PlayerScripts.Fireball:11: attempt to get length of global 'parts' (a nil value) hh9man 5 — 6y
0
You have to define `parts`. Do local parts = Player.Character:GetChildren() chomboghai 2044 — 6y
0
I did that and the script still doesnt work, do you think you could type exactly how you would put it? I would appreciate it. hh9man 5 — 6y
Ad

Answer this question