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

When a part anchors it flings me off?

So im making an obby where when the player presses Q every part in the workspace gets anchored, But when i use this the part still has avelocity even after me setting the velocity to 0, how do i fix this?

local usi = game:GetService("UserInputService")
usi.InputBegan:Connect(function(input,typing)
	if typing then
		return
	elseif input.KeyCode == Enum.KeyCode.Q then
		for i,v in pairs(workspace:GetChildren()) do
			if v:IsA('Part') or v:IsA('MeshPart') then
				if not v:FindFirstChild('Value') then
					if v.Anchored == true then
					v.Anchored = false
					elseif v.Anchored == false then
						v.Anchored = true
				end
			end
		end
	end
end)

-- This goes in Starter Pack

Thanks for the help!

1 answer

✓ Accepted answer

I think it's because you are using :GetChildren() instead of :GetDescendants(). :GetChildren only gets whatever is directly under the object (in this case workspace), not all of that childs descendants.

In your case, whatever part you are trying to remove the velocity from could be under another child, so it wouldn't get set to 0.

Give this a shot and let me know if it worked!

Code:

local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(input, typing)
    if typing then
        return end
    elseif input.KeyCode == Enum.KeyCode.Q then
        for i, v in pairs(game.Workspace:GetDescendants()) do
            if v:IsA('Part') or v:IsA('MeshPart') then
                if not v:FindFirstChild('Value') then
                    if v.Anchored == true then
                    	v.Anchored = false
                    elseif v.Anchored == false then
                        v.Anchored = true
                end
            end
        end
    end
end)

-- This goes in Starter Pack

p.s make sure to accept my answer if it helped!

1 comment

0

Thanks!

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